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
Doc: HibernateJpaVendorAdapter's "prepareConnection" may interfere with Hibernate 5.1+ in a JTA environment [SPR-14957] #19524
The reporter experiences a difference of behaviour when OpenEntityManagerInViewFilter is enabled on a Spring MVC application using Weblogic and Hibernate 5.1 or 5.2. The same code works fine with 5.0
I am wondering if that's a regression in our Hibernate support or in Hibernate itself.
For 5.1.x, using these settings (just to override the automatic override in HibernateJpaVendorAdapter), this issue doesn't manifest itself in jta anymore
For 5.2.x, using these settings (just to override the automatic override in HibernateJpaVendorAdapter), this issue doesn't manifest itself in jta anymore
In 5.0.x the default mode for JdbcResourceLocalTransaction was indeed ON_CLOSE, however for JtaTransaction it was AFTER_STATEMENT. It looks like this wasn't taken into account when the 'revert' to the default mode was added.
This is essentially a known issue: HibernateJpaVendorAdapter.setPrepareConnection mentions the enforced DELAYED_ACQUISITION_AND_HOLD mode on Hibernate 5.2 already. Admittedly, this should more explicitly mention JTA setups and WebLogic in particular... and have a dedicated note in the reference documentation as well.
The underlying technical problem is that we can't influence Hibernate's connection release mode depending on the transaction setup: simply because JPA doesn't allow us to reliably introspect the transaction setup in general. As a consequence, HibernateJpaVendorAdapter leans towards optimizing our common case: Spring-driven resource transactions with full control over the lifecycle of the underlying connection, which requires ON_CLOSE connection mode semantics. Hibernate has been changing the default a few times over the years, and our general policy is to enforce ON_CLOSE by default whenever we need to.
The easiest way out would be to set HibernateJpaVendorAdapter's "prepareConnection" flag to false, or to not use HibernateJpaVendorAdapter in a WebLogic JTA setup to begin with. Of course you may also simply override the corresponding Hibernate property, as you suggested.
Activity
spring-projects-issues commentedon Nov 27, 2016
Alexandru-Constantin Bledea commented
I also opened an issue on the hibernate issue tracker
spring-projects-issues commentedon Nov 28, 2016
Alexandru-Constantin Bledea commented
This is the commit that breaks the previous behavior
spring-projects-issues commentedon Nov 28, 2016
Alexandru-Constantin Bledea commented
It looks like the issue is setting the default modes for spring 5.1.x and spring 5.2.x
For 5.1.x, using these settings (just to override the automatic override in HibernateJpaVendorAdapter), this issue doesn't manifest itself in jta anymore
For 5.2.x, using these settings (just to override the automatic override in HibernateJpaVendorAdapter), this issue doesn't manifest itself in jta anymore
In 5.0.x the default mode for JdbcResourceLocalTransaction was indeed ON_CLOSE, however for JtaTransaction it was AFTER_STATEMENT. It looks like this wasn't taken into account when the 'revert' to the default mode was added.
spring-projects-issues commentedon Nov 28, 2016
Juergen Hoeller commented
This is essentially a known issue:
HibernateJpaVendorAdapter.setPrepareConnectionmentions the enforcedDELAYED_ACQUISITION_AND_HOLDmode on Hibernate 5.2 already. Admittedly, this should more explicitly mention JTA setups and WebLogic in particular... and have a dedicated note in the reference documentation as well.The underlying technical problem is that we can't influence Hibernate's connection release mode depending on the transaction setup: simply because JPA doesn't allow us to reliably introspect the transaction setup in general. As a consequence,
HibernateJpaVendorAdapterleans towards optimizing our common case: Spring-driven resource transactions with full control over the lifecycle of the underlying connection, which requiresON_CLOSEconnection mode semantics. Hibernate has been changing the default a few times over the years, and our general policy is to enforceON_CLOSEby default whenever we need to.The easiest way out would be to set
HibernateJpaVendorAdapter's "prepareConnection" flag tofalse, or to not useHibernateJpaVendorAdapterin a WebLogic JTA setup to begin with. Of course you may also simply override the corresponding Hibernate property, as you suggested.