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.
Juergen Hoeller opened SPR-17002 and commented
As outlined in #21494 and #21454, it is desirable for the Hibernate
LocalSessionFactoryBean
to be usable for JPAEntityManagerFactory
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 forLocalContainerEntityManagerFactoryBean
for Hibernate JPA setup purposes. The same goes forHibernateTransactionManager
which should work fine as a replacement forJpaTransactionManager
in such a scenario, just with stronger Hibernate-specific behavior.Issue Links:
The text was updated successfully, but these errors were encountered: