1

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",offset=-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_WEEK_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
Gaurav
  • 31
  • 1
  • 5
  • hows the hibernate envers get hooked after jta commit normal entity ? itw ill help me in debug – Gaurav Apr 04 '13 at 05:49
  • In 3.5 Envers registers a transaction synchronization. Look at the AuditSync class, and the beforeCompletion() method. Does it get called? – adamw Apr 04 '13 at 18:24
  • I cannot see AuditSync class. under org.hibernate.envers.synchronization package I can see only AuditProcess and AuditProcessManager. I am using hibernate-envers-3.5.1-Final – Gaurav Apr 05 '13 at 06:32
  • Ah sorry, looked at the wrong version :) I meant AuditProcess (https://github.com/hibernate/hibernate-orm/blob/3.5/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java). The `beforeCompletion()` method should be called, and some work units should be executed. – adamw Apr 06 '13 at 09:59
  • beforecompletion method is not getting called. the debugger doesn't even enter this Class. – Gaurav Apr 07 '13 at 06:16
  • i have removed atomikos transaction manager and using spring's ..and now everything is working fine... – Gaurav Apr 07 '13 at 06:17
  • I had the same issue. Please try [this](http://stackoverflow.com/questions/25664034/envers-doesnt-insert-records/25748380#25748380) hope this help. – jmj Nov 20 '15 at 20:05

2 Answers2

1

In my case upgrading from envers 3.5.1 to 3.5.6 fixed the problem.

Krever
  • 1,371
  • 1
  • 13
  • 32
0

I have perform some testing namely: JTA + envers +

  1. hibernate 3.6.1 - commit errors
  2. hibernate 4 - commits finish without errors but the data is not persisted
  3. jpa (hibernate 4) - everything works fine

I've used JBoss as my container and Oracle (XA configuration) as my DB.

Configuration without JTA generates no problem regardless envers version

bmichalik
  • 196
  • 6