• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to reduce the boilerplate code in entitymanager in spring mvc ?  RSS feed

 
Muztaba Hasanat
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very new to hibernate and jpa world. With hibernate `sessionFactory` I have write a criteria dynamic query like -


But some reading I have found that using EntityManager over SessionFactory make the code loosely couple with the hibernate implementation. So I have changed my code like this. -

Using EntityManager the code looks like much more verbose. On the other hand the first one using SessionFactory the code is much more cleaner. My question is, Using EntityManager is the only way to deal with criteria dynamic query or there are some cleaner way to do ?

Thank you.
 
Roel De Nijs
Sheriff
Posts: 11096
173
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muztaba Hasanat wrote:My question is, Using EntityManager is the only way to deal with criteria dynamic query or there are some cleaner way to do ?

It seems you are not the only one with this concern. And here is a SO question about the same topic. And in this blog article you can find some pros of using the (more verbose) Criteria API. And there are also some other frameworks claiming to provide easier and less verbose criteria APIs, like Querydsl.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!