6 Replies Latest reply on Apr 3, 2013 1:04 PM by Gary M

    No version records created when using JTA transaction manage

    Daniel Meyer Newbie

      Does envers work with a JTA transaction manager? I'm using Spring 2.5.5 and JBoss 4.2.2.GA, and when I use the Hibernate 3 transaction manager, envers versioning records are created, but when I use the JTA transaction manager, no versioning records are created.

      Even if Spring-specific help is not available, it would be good to know if envers is known to work with a JTA transaction manager. Is there some envers setup specific to JTA that I'm missing?

      Hibernate 3 transaction manager bean that results in envers versioning records being written as expected:

      <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
       <property name="sessionFactory" ref="sessionFactory" />
      </bean>


      JTA transaction manager bean that unexpectedly results in no envers versioning records being written:
      <tx:jta-transaction-manager />


      -Daniel-

        • 1. Re: No version records created when using JTA transaction ma
          Adam Warski Master

          Hello,

          as long as the transaction is commited, everything should work fine. I tested with resource-local transactions and container-manager transactions (in a seam web app) and both worked. Maybe others have some experiences with Spring which they could share :)

          --
          Adam

          • 2. Re: No version records created when using JTA transaction ma
            talios Newbie

            We've been using Envers with JTA/XA using Atomikos without problems (beyond my normal envers related issues). But it works fine with JTA.

            • 3. Found the answer
              Daniel Meyer Newbie

              I found the issue: I needed to specify hibernate.transaction.manager_lookup_class and hibernate.transaction.factory_class in my hibernate config, as documented here:

              http://www.hibernate.org/42.html#A5

              I wrote up my meanderings here, for those who like sagas. :)

              -Daniel-

              • 5. Re: No version records created when using JTA transaction ma
                Adam Warski Master

                Hello,

                great! I'm sure this will help a lot of other Spring users :)
                I have linked to your blog from the new wiki page:
                https://www.jboss.org/community/docs/DOC-13216
                I hope you don't mind :)

                I've also linked to the FAQ from the main page.

                --
                Adam

                • 6. Re: No version records created when using JTA transaction ma
                  Gary M Newbie

                  Hi Talios can you share your config file. I am getting problem in getting envers working with Atomikos JTA

                   

                   

                   

                  I am facing similar problem. I am using Spring 3.1, Spring data jpa 1.2 with Hibernate 3.5.1 and envers 3.5.1. The issue is when using envers my _AUD table is getting created but the data is not

                   

                   

                  inserted in the AUD tables. I have used @Audited on Person entity and created RevListener class implements RevisionListener. Also I have created RevEntity extending

                   

                   

                  DefaultRevisionEntity as mentioned in envers doc. When I try to run my Spring junit test by simply using @Rollback(false) and using PersonRepository save method. It

                   

                   

                  is saving New person in the database but nothing is inserted in Person_AUD table. Below is the snippet from my spring config fie.

                   

                   

                  <bean id="atomikosTransactionManager"   class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init"

                                      destroy-method="close">

                                      <property name="forceShutdown" value="true" />

                                      <property name="startupTransactionService" value="true" />

                   

                   

                              </bean>

                  <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">

                              <property name="transactionTimeout" value="1000" />

                              </bean>

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

                                  <property name="transactionManager" ref="atomikosTransactionManager" />

                                  <property name="userTransaction" ref="atomikosUserTransaction" />

                                  <property name="transactionSynchronizationName"  value="SYNCHRONIZATION_ON_ACTUAL_TRANSACTION" />

                              </bean>

                   

                   

                              <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" id="PPL_GMRJPAVendorAdapter">

                                      <property name="showSql" value="true"/>

                                      <property name="generateDdl" value="true"/>

                                      <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>

                              </bean>

                   

                   

                              <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="PPL_GMR">

                                      <property name="dataSource" ref="PPL_GMRDS"></property>

                                      <property name="persistenceUnitName" value="PPL_GMR"/>

                                      <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-test.xml"/>

                                      <property name="jpaVendorAdapter" ref="PPL_GMRJPAVendorAdapter"/>

                                      <property name="jpaPropertyMap">

                                              <map>

                                                  <entry key="hibernate.transaction.manager_lookup_class"                                                    

                   

                   

                   

                   

                   

                   

                                          value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>

                                                          <entry key="hibernate.default_schema" value="${PPL.schema}"/>

                                                  <entry key="hibernate.hbm2ddl.auto" value="update"/>

                                                  <entry key="org.hibernate.envers.auditTablePrefix" value=""/>

                                                  <entry key="org.hibernate.envers.auditTableSuffix" value="_AUD"/>

                   

                   

                                                  <entry key="hibernate.transaction.flush_before_completion" value="false"/>

                                                      <entry key="hibernate.transaction.auto_close_session" value="true"/>

                                                      <entry key="hibernate.current_session_context_class" value="jta"/>

                                                      <entry key="hibernate.connection.release_mode" value="auto"/>

                   

                   

                                              </map>

                                      </property>

                              </bean>

                  Here is excerpt from my persistence.xml

                   

                   

                  <properties>

                      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>

                       <property name="hibernate.ejb.event.post-insert"

                               value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />

                            <property name="hibernate.ejb.event.post-update"

                               value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />

                            <property name="hibernate.ejb.event.post-delete"

                               value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />

                            <property name="hibernate.ejb.event.pre-collection-update"

                               value="org.hibernate.envers.event.AuditEventListener" />

                            <property name="hibernate.ejb.event.pre-collection-remove"

                               value="org.hibernate.envers.event.AuditEventListener" />

                            <property name="hibernate.ejb.event.post-collection-recreate"

                               value="org.hibernate.envers.event.AuditEventListener" />            

                      </properties>

                  </persistence>

                  I also try adding this property to entitymanager config "hibernate.transaction.factory_class"value="com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory"

                   

                   

                  but after adding this now the data is not getting inserted in the person table also. And in the AUD table as usual data is not getting inserted. Person object created

                   

                   

                  is displayed but not committed.

                   

                   

                  This is the last few lines of the log in debug mode

                   

                   

                  2013-04-03 11:47:39 DEBUG AbstractEntityManagerImpl:990 - Looking for a JTA transaction to join

                  2013-04-03 11:47:39 WARN  AbstractEntityManagerImpl:1099 - Cannot join transaction: do not override hibernate.transaction.factory_class

                  2013-04-03 11:47:40 DEBUG TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource:288 - Adding transactional method 'save' with

                  attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' 2013-04-03 11:47:40 DEBUG JDBCContext:199 - successfully registered Synchronization 2013-04-03 11:47:40 DEBUG SessionImpl:257 - opened session at timestamp: 13650040606 2013-04-03 11:47:40 DEBUG AbstractEntityManagerImpl:990 - Looking for a JTA transaction to join 2013-04-03 11:47:40 WARN AbstractEntityManagerImpl:1099 - Cannot join transaction: do not override hibernate.transaction.factory_class 2013-04-03 11:47:40 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0) 2013-04-03 11:47:40 DEBUG ConnectionManager:444 - opening JDBC connection 2013-04-03 11:47:40 DEBUG SQL:111 - select GMRPPLD4.PERSON_SEQ.nextval from dual Hibernate: select GMRPPLD4.PERSON_SEQ.nextval from dual 2013-04-03 11:47:40 DEBUG SequenceGenerator:114 - Sequence identifier generated: BasicHolder[java.lang.Integer[21]] 2013-04-03 11:47:40 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1) 2013-04-03 11:47:40 DEBUG ConnectionManager:427 - aggressively releasing JDBC connection 2013-04-03 11:47:40 DEBUG ConnectionManager:464 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)] 2013-04-03 11:47:40 DEBUG SequenceHiLoGenerator:85 - new hi value: BasicHolder[java.lang.Integer[21]] 2013-04-03 11:47:40 DEBUG AbstractSaveEventListener:135 - generated identifier: 1050, using strategy: org.hibernate.id.SequenceHiLoGenerator Persons: id=[1050]

                   

                   

                  birthDate=[java.util.GregorianCalendar[time=1365004060605,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",off

                   

                   

                  set=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight

                   

                   

                  =true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,

                   

                   

                  endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=3,WEEK_OF_YEAR=14,WEEK_OF_MONTH=1,DAY_OF_MONTH=3,DAY_OF_YEAR=93,DAY_OF_WEEK=4,DAY_OF_WE

                   

                   

                  EK_IN_MONTH=1,AM_PM=0,HOUR=11,HOUR_OF_DAY=11,MINUTE=47,SECOND=40,MILLISECOND=605,ZONE_OFFSET=-18000000,DST_OFFSET=3600000]] 2013-04-03 11:47:40 WARN EntityManagerImpl:138 - Entity Manager closed by someone else (hibernate.transaction.auto_close_session must not be used) 2013-04-03 11:47:41 INFO SessionFactoryImpl:935 - closing 2013-04-03 11:47:41 INFO SessionFactoryImpl:935 - closing