Skip to content

Doc: HibernateJpaVendorAdapter's "prepareConnection" may interfere with Hibernate 5.1+ in a JTA environment [SPR-14957] #19524

Closed

Description

@spring-projects-issues

Stéphane Nicoll opened SPR-14957 and commented

See spring-projects/spring-boot#7455 (a sample is available).

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.


Affects: 4.3.4

Issue Links:

Referenced from: commits 2f80b84, 04af30d

Activity

  1. spring-projects-issues commented on Nov 27, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Alexandru-Constantin Bledea commented

    I also opened an issue on the hibernate issue tracker

  2. spring-projects-issues commented on Nov 28, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Alexandru-Constantin Bledea commented

    This is the commit that breaks the previous behavior

  3. spring-projects-issues commented on Nov 28, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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

        <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="persistenceUnitName" value="default"/>
            <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
            <property name="jpaPropertyMap">
                <map>
                    <entry key="hibernate.connection.release_mode" value="auto"/>
                </map>
            </property>
        </bean>

    For 5.2.x, using these settings (just to override the automatic override in HibernateJpaVendorAdapter), this issue doesn't manifest itself in jta anymore

        <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="persistenceUnitName" value="default"/>
            <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
            <property name="jpaPropertyMap">
                <map>
                    <entry key="hibernate.connection.handling_mode" value="DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT"/>
                </map>
            </property>
        </bean>

    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.

  4. spring-projects-issues commented on Nov 28, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    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.

  5. added
    in: data
    type: task
    on Jan 11, 2019
  6. added this to the 4.3.5 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: task

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions