• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic