Do you like the Criteria api of JPA 2.0? Do you use it with framework?

Sebastien Lorber picture Sebastien Lorber · May 6, 2011 · Viewed 7.1k times · Source

I'm used to work with Criteria API in Hibernate, and just watched how the Criteria in JPA 2.0 work.

What i like most in the Criteria of Hibernate is the ease we have to compose with Criterions.

The JPA Criteria seems quite heavy for me, and not as fluent as the Hibernate Criteria. One of the major benefits compared to Hibernate for me seems to be the use of the metamodel (Entity_.java classes), but still it's a bit heavy too since you have to maintain 2 classes, or add an annotation processor (though its quite easy to integrate with maven plugins)

I've read a blog on SpringSource that permits to reduce the complexity of composing with "JPA Predicates" and do a bit like with Criterions in Hibernate.

The Querydsl project seems interesting.

http://blog.springsource.com/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/

Just wonder, for those using JPA2, are you using Criteria API or it's a bit too heavy for you?

For those familiar with Hibernate Criteria and who now work with JPA Criteria, dowhich approach do you like the most and why?

Are you considering of using, or using, a framework like Querydsl or Spring Specifications over JPA2 for building your query predicates? Do you think these frameworks are mature enough to be adopted?

Answer

DataNucleus picture DataNucleus · May 6, 2011

No, don't like it, due to the lack of expressability and fluency in the API. Yes QueryDSL does the same in less code, and more naturally. For that reason we've taken the same route for JDO's own typesafe query API, comparing it to JPA Criteria https://datanucleus.wordpress.com/2010/11/09/jdo-typesafe-vs-jpa-criteria/