JPA 2.0 with Criteria

(see: JSR 317 Persistently Improving)

I love the idea of adding a criteria API to JPA, the only thing I hope that they do differently than Hibernate is to implement that API in addition to string queries.  In Gauntlet we had issues where we wanted to use EJB-QL for selecting the right data and then a criteria-like API for applying security and filtering constraints on the query.  We ended up writing a criteria-like API that augmented the WHERE clause of the query to get the behavior that we needed (like described here).  For example, you could do this:

Query q = em.createQuery("SELECT p FROM Project p");
q.addExpression(Expression.notEqual("id", 2));

Or something like that. This would give you the best of both worlds, where you have the expressiveness of the textual query and the ability to further hone that query programmatically.

This entry was posted in Java, Technology, gauntlet and tagged , , , , , . Bookmark the permalink.

4 Responses to JPA 2.0 with Criteria

  1. murali says:

    java source code

  2. luke says:

    Thats good idea.

  3. luke says:

    Thats good idea.

  4. For another approach to get the best of both worlds, consider using Querydsl : http://source.mysema.com/display/querydsl

    Querydsl is fully type-safe, has an JPQL like syntax and supports incremental query definition.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

blog comments powered by Disqus