I have seen in lot of forums and still in confusion. We are starting a new project with Spring 3.1 & Hibernate 4 and need to decide which strategy to use for Hibernate with Spring:
Accessing Hibernate directly
Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();
Using HibernateTemplate
List bb = (List)hibernateTemplate.find("from Entity");
Using HibernateDAOSupport classes
List bb =(List)getHibernateTemplate().find("from Entity");
Can you please help what should i use? I have read from CodeRanch and one another link which tell that from Hibernate 3.x onwards we should inject SessionFactory
in our DAO Classes(using @Repository
).
Can someone explain this in detail?
Regards,
Arun Kumar
Spring itself recommends not using HibernateTemplate anymore, in the javadoc of the class. You can declare the session factory as a Spring bean directly, inject it as any other Spring bean in your own components, and use the native Hibernate API directly (using sessionFactory.getCurrentSession()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With