0

In real time which one is recommended among HibernateTemplate, sessionFactory.openSession() or sessionFactory.getCurrentSession()?

And in your experience, what is used from the above mentioned in live running web project with spring mvc+ hibernate ?

Pardhu
  • 11
  • 3

1 Answers1

0

HibernateTemplate supposed to wrap the overhead of session management so using it is the easier among these 3 options and also more save than working with session direct, and you can manage transaction then with transaction manager for ex. with @Transactional, you can check also the Spring data JPA project, it is more robust and decoupling your development from the ORM framework you are using.

Bassem Reda Zohdy
  • 12,662
  • 3
  • 33
  • 39
  • Thank you for the replay. I have seen that HibernateTemplate is not recommended in [this link](http://stackoverflow.com/questions/18002768/why-hibernatetemplate-isnt-recommended). And HibernateTemplate is not uses thread-safe session seen in [this link](http://forum.spring.io/forum/spring-projects/data/7427-can-hibernatetemplate-get-thread-safe-session) – Pardhu Jan 17 '17 at 06:23
  • Only concern I can see that "unnecessarily ties your code to Spring classes" and if you are using spring for transaction management, so you already coupled, and most of these concerns can be avoided by using spring Data. – Bassem Reda Zohdy Jan 17 '17 at 07:32