I am developing Spring MVC Hibernate
Integration example. In this example I\'m using Spring 4.1.9.RELEASE
and Hibernate 5.1.0.Final
. If I
I wanted to create an application context that works well for both Hibernate 4 and Hibernate 5 at the same time.[why?]
So I replaced Hibernate-specific transaction manager (org.springframework.orm.hibernate4.HibernateTransactionManager
) with Spring JPA transaction manager (org.springframework.orm.jpa.JpaTransactionManager
):
// part of my Java Config
@Bean
@Autowired
public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory, DataSource mainDataSource) {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory);
transactionManager.setDataSource(mainDataSource);
return transactionManager;
}
[why?] Because this context is shared between different modules that depend on different Spring and Hibernate versions.