Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9883

Inconsistent behavior for LocalContainerEntityManagerFactoryBean for using/not using persistence.xml, with Hibernate4

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.1.2
    • Fix Version/s: 3.1.3, 3.2 RC1
    • Component/s: Data:ORM
    • Labels:
      None

      Description

      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:

      app context xml snippet
       
      <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

      app context xml snippet
       
      <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.xml
       
      <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.

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              adrianshum Adrian Shum
              Last updater:
              Matthias Müller
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 46 weeks, 3 days ago