Question - How to integrate Hibernate and Spring?
Answer -
Spring is also one of the most commonly used Java frameworks in the market today. Spring is a JavaEE Framework and Hibernate is the most popular ORM framework. This is why Spring Hibernate combination is used in a lot of enterprise applications.
Following are the steps you should follow to integrate Spring and Hibernate.
- Add Hibernate-entity manager, Hibernate-core and Spring-ORM dependencies.
- Create Model classes and corresponding DAO implementations for database operations. The DAO classes will use SessionFactory that will be injected by the Spring Bean configuration.
- Note that you don’t need to use Hibernate Transaction Management, as you can leave it to the Spring declarative transaction management using @Transactional annotation.