Hibernate 5 SpringSessionSynchronization calls Session.getFlushMode() directly instead of using SessionFactoryUtils.getFlushMode(session) [SPR-14364] #18936
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
type: regression
A bug that is also a regression
Milestone
Manuel Dominguez Sarmiento opened SPR-14364 and commented
Hibernate 5.2.0 changed the method signature for Session.getFlushMode() so that it returns a javax.persistence.FlushModeType instead of a org.hibernate.FlushMode
Spring 4.3.0 introduced several changes so that it could remain compatible with both 5.1.0 and 5.2.0 mainly by introducing indirection to obtain the Hibernate flush mode through SessionFactoryUtils.getFlushMode(session). However, this necessary change was omitted from SpringSessionSynchronization which still uses the following code snippet in beforeCommit():
which should now be:
This has critical consequences. Due to this bug, Spring 4.3.0 is not compatible with either Hibernate 5.1.0 nor 5.2.0
When using Hibernate 5.1.0 this bug causes a java.lang.NoSuchMethodError due to the method signature change:
java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Ljavax/persistence/FlushModeType;
at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:101)
While in Hibernate 5.2.0 this causes javax.persistence.TransactionRequiredException due to equals(FlushMode.MANUAL) always returning false since it is comparing javax.persistence.FlushModeType vs org.hibernate.FlushMode
javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3392)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1385)
at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:104)
Affects: 4.3 GA
The text was updated successfully, but these errors were encountered: