我使用Spring 3.1,Spring数据jpa 1.2与Hibernate 3.5.1和envers 3.5.1。问题是当使用envers我的_AUD表被创建但数据没有插入AUD表。我在Person实体上使用了@Audited,并创建了RevListener类,实现了RevisionListener。我还创建了RevEntity,扩展了Envers doc中提到的DefaultRevisionEntity。当我尝试通过简单地使用@Rollback(false)并使用PersonRepository save方法来运行我的Spring junit测试时。它在数据库中保存新人,但在Person_AUD表中没有插入任何内容。下面是我的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>
以下是我的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>
我也尝试将此属性添加到entitymanager config“hibernate.transaction.factory_class”value =“com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory”但是现在添加此数据之后,数据也没有插入到person表中。并且在AUD表中通常没有插入数据。创建的Person对象显示但未提交。
这是调试模式下日志的最后几行
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
答案 0 :(得分:1)
在我的情况下,从envers 3.5.1升级到3.5.6修复了问题。
答案 1 :(得分:0)
我已经进行了一些测试: JTA + envers +
我使用JBoss作为我的容器,使用Oracle(XA配置)作为我的数据库。
无论版本
,没有JTA的配置都不会产生任何问题