Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session from SessionFactory.getCurrentSession not synchronized with current JPA transaction on Hibernate 5.2 [SPR-16915] #21454

Closed
spring-projects-issues opened this issue Jun 7, 2018 · 1 comment
Assignees
Labels
in: data status: declined type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jun 7, 2018

Marten Deinum opened SPR-16915 and commented

When using Hibernate 5.2 and using an unwrapped (or cast) SessionFactory to get the current session using getCurrentSession this doesn't get synchronized with the current transaction. 

This is mainly due to the change in Hibernate 5.2 that Session now extends EntityManager which will create an unsynchronized EntityManager leading to an exception when the transaction will commit. 

This all happens in the invokeProxyMethod in the AbstractEntityManagerFactoryBean. I guess that method should also treat the getCurrentSession method like it does the createEntityManager method with SynchronizationType.SYNCHRONIZED is used. 

NOTE: This only happens with Hibernate 5.2 (or up) with lower versions there (probably) isn't an issue as there Session doesn't extend EntityManager.


Affects: 4.3.17, 5.0.6

Issue Links:

  • #21540 LocalSessionFactoryBean and HibernateTransactionManager for JPA EntityManagerFactory setup
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 3, 2018

Juergen Hoeller commented

From my current perspective, SessionFactory.getCurrentSession() is not a supported feature with a plain JPA setup. Adding support for it to our general JPA setup classes would hard-code Hibernate specifics into it, and adding dedicated support for it to the JpaVendorAdapter abstraction is quite a bit of hassle.

As outlined in #21494, I'm rather keen on the use of LocalSessionFactoryBean even for JPA EntityManagerFactory setup... in particular for a mix of native Hibernate and standard JPA access. If there are any issues with that kind of setup, I'd definitely consider fine-tuning that area for Spring Framework 5.1 still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data status: declined type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants