Django-like queries in Java / JPA

Is there any library or framework for JPA requests in a less logical way, for example:

User.query("age < 30") 

instead:

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

I believe that there is no standard way to do this with JPA. I saw the Hibernate Criteria API , it is not as simple as Django and makes the application connect to Hibernate. I would like to know what you think about this and other approaches.

+4
source share
3 answers

Yes, the Java framework allows you to do this: Play! framework This is a structure similar to Django, but completely written using Java. http://www.playframework.org/documentation/1.0.1/model

For example, you can write something like:

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

In addition, it is not related to hibernation, you can use other technologies, such as Google App Engine data warehouse or Amazon Simple DB throw Siena

+5
source

You can make the request shorter:

 from User where age < 30 

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

+2
source

In this regard, I also discovered that Spring Roo can generate objects following this Active Record Pattern, and allows the developer to include search methods.

+1
source

Source: https://habr.com/ru/post/1299871/


All Articles