You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LocalSessionFactoryBean and HibernateTransactionManager for JPA EntityManagerFactory setup [SPR-17002] #21540
As outlined in #21494 and #21454, it is desirable for the Hibernate LocalSessionFactoryBean to be usable for JPA EntityManagerFactory setup as well: that is, in a first-class fashion with out-of-the-box integration with other JPA facilities such as @PersistenceContext injection, making it a replacement for LocalContainerEntityManagerFactoryBean for Hibernate JPA setup purposes. The same goes for HibernateTransactionManager which should work fine as a replacement for JpaTransactionManager in such a scenario, just with stronger Hibernate-specific behavior.
SessionHolder extends EntityManagerHolder now, allowing for @PersistenceContext and co to interact with HibernateTransactionManager's thread-bound transactions, and SpringSessionContext (backing SessionFactory.getCurrentSession()) is capable of interacting with JpaTransactionManager by detecting a plain EntityManagerHolder as well.
This covers a lot of ground for a start: With Hibernate 5.2 and 5.3, LocalSessionFactoryBean and HibernateTransactionManager serve as a 99%-compatible replacement for LocalContainerEntityManagerFactoryBean and JpaTransactionManager in many scenarios, allowing for interaction with SessionFactory.getCurrentSession() (and also HibernateTemplate) next to @PersistenceContext EntityManager interaction within the same local transaction (#21454). That aside, such a setup also provides stronger Hibernate integration (#21494, #20852) and more configuration flexibility, not being constrained by JPA bootstrap contracts.
Activity
spring-projects-issues commentedon Jul 4, 2018
Juergen Hoeller commented
SessionHolderextendsEntityManagerHoldernow, allowing for@PersistenceContextand co to interact withHibernateTransactionManager's thread-bound transactions, andSpringSessionContext(backingSessionFactory.getCurrentSession()) is capable of interacting withJpaTransactionManagerby detecting a plainEntityManagerHolderas well.This covers a lot of ground for a start: With Hibernate 5.2 and 5.3,
LocalSessionFactoryBeanandHibernateTransactionManagerserve as a 99%-compatible replacement forLocalContainerEntityManagerFactoryBeanandJpaTransactionManagerin many scenarios, allowing for interaction withSessionFactory.getCurrentSession()(and alsoHibernateTemplate) next to@PersistenceContext EntityManagerinteraction within the same local transaction (#21454). That aside, such a setup also provides stronger Hibernate integration (#21494, #20852) and more configuration flexibility, not being constrained by JPA bootstrap contracts.