tags:

views:

155

answers:

2

Is there any library or framework to make JPA queries in a less verbose way such as:

User.query("age < 30")

instead of:

Query query = entityManager.createQuery("select u FROM User u WHERE age < 30");
return query.getResultList();

I suppose there is no standard way to do it with JPA. I've seen Hibernate Criteria API, that is not as simple as Django and forces your application to be coupled to Hibernate. I'd like to know what do you think about it and other approaches.

+1  A: 

You can make your query shorter:

from User where age < 30

Additionally I would like to add that the Hibernate API is much more powerful and adds things like polymorphism and prefetching in a nice way, so don't give up on it yet.

disown
Thank you. Any good link about Hibernate polymorphism and prefetching?
Guido
Look at the hibernate docs for HQL, 14.3 covers fetching and 14.8 polymorphic queries. 14.15 and 16 are good too.
disown
http://docs.jboss.org/hibernate/stable/core/reference/en/html/queryhql.html
disown
+1  A: 

Yes, a Java framework allow you to do that: Play! framework. It's a framework similar to Django but complety written using Java. http://www.playframework.org/documentation/1.0.1/model

For instance you can write something like:

User.find("age< ?", 30).fetch();

Moreover this is not coupled to hibernate you can use other technologies like Google App Engine datastore or Amazon Simple DB throw Siena

lgu
Interesting. Some sections are experimental (SimpleDB) or seem to be under construction (Siena-remote).
Guido
One thing I don't like is the need to extend your domain classes from "siena.Model", because Java does not support multiple inheritance.
Guido