Skip to content

Inconsistent behavior for LocalContainerEntityManagerFactoryBean for using/not using persistence.xml, with Hibernate4 [SPR-9883] #14516

@spring-projects-issues

Description

@spring-projects-issues

Adrian Shum opened SPR-9883 and commented

The finding is triggered by the transaction/auto-flushing problem I encountered and discussed in the reference URL.

I am using Spring 3.1.2, Hibernate 4.1.6, WebSphere 8

The symptoms is: If I use LocalContainerEntityManagerFactoryBean (Lemme call it LCEMFB) without persistence.xml, when I am performing transactional actions (e.g. flushing the entity manager (em) ), it complains for no transaction in progress (It seems to me that Hibernate is unable to lookup the transaction). However if I use the traditional way to have a persistence.xml which contains almost identical settings, it works without problem.


Here is the non-persistence.xml config:

snippet in app context xml:

 
<jee:jndi-lookup  id="dataSource" jndi-name="jdbc/fooDs" />

<bean id="transactionManager"
    class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />

<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
        </bean>
    </property>
    <property name="persistenceUnitName" value="foo" />
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.foo" />

    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform"/>
            <entry key="hibernate.current_session_context_class" value="jta" />
            <entry key="hibernate.transaction.flush_before_completion"  value = "true" />
        </map>
    </property>
</bean>

(No META-INF/persistence.xml)

Such way to config LCEMFB give me problem of "no transaction in progress", or failed "auto-flushing" (please refer to reference URL for different behavior with different jpaPropertyMap combination)


However, if I switch the whole setting to

 
<jee:jndi-lookup  id="dataSource" jndi-name="jdbc/fooDs" />

<bean id="transactionManager"
    class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />

<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="foobar" />
</bean>
 
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="foobar" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/fooDs</jta-data-source>

        <class>com.foo.FooModel</class>

        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" />
            <property name="hibernate.current_session_context_class" value="jta"/>
            <property name="hibernate.transaction.flush_before_completion" value="true"/>
            <property name="hibernate.connection.release_mode" value="auto"/>
        </properties>
    </persistence-unit>
</persistence>

Though the configuration is almost identical, the "no persistence.xml" way is not giving result as expected.


Affects: 3.1.2

Reference URL: http://forum.springsource.org/showthread.php?131051-Auto-Flush-not-working-for-Spring-3-1-LocalEntityManagerFactoryBean-Hibernate-4-JTA

Referenced from: commits 4ff7654, 7702fb8

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions