I have been updating the frameworks on my application and now I'm trying to configure hibernate envers with JPA to audit some domains.
Regular persistence is working properly by Audit is failing with the error below
I've got this error
org.springframework.orm.hibernate4.HibernateSystemException: Unable to create revision because of non-active transaction; nested exception is org.hibernate.envers.exception.AuditException: Unable to create revision because of non-active transaction
at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:218)
at org.springframework.orm.hibernate4.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:107)
....
My configuration is:
<!-- How to include more then one base package -->
<!--Activates various annotations to be detected in bean classes: Spring's @Required and @Autowired and so on-->
<context:annotation-config/>
<!--Scanning components in base-package (look for annotations) -->
<context:component-scan base-package="com.lotjm"/>
<context:property-placeholder location="classpath:./properties/database.properties"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="packagesToScan" value="com.lotjm"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false"/>
<property name="showSql" value="true" />
</bean>
</property>
<property name="jpaPropertyMap">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
<prop key="org.hibernate.envers.audit_strategy_validity_store_revend_timestamp">true</prop>
</props>
</property>
<property name="persistenceProvider">
<bean class="org.hibernate.jpa.HibernatePersistenceProvider"></bean>
</property>
</bean>
<!-- Need for Repository abstraction -->
<jpa:repositories base-package="com.lotjm.repository"
factory-class="org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean"/>
<tx:annotation-driven transaction-manager="transactionManager" order="1"/>
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.lotjm.domain.User</value>
<value>com.lotjm.domain.Application</value>
<value>com.lotjm.domain.Project</value>
<value>com.lotjm.domain.Document</value>
<value>com.lotjm.domain.AbstractAuditingEntity</value>
</list>
</property>
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
</bean>
<bean id="auditingProvider" class="com.lotjm.config.audit.UsernameAuditorAware"/>
<bean id="dateTimeService" class="com.lotjm.config.audit.CurrentTimeDateTimeService"/>
<bean id="dateTimeProvider" class="com.lotjm.config.audit.AuditingDateTimeProvider">
<constructor-arg index="0" ref="dateTimeService"/>
</bean>
<jpa:auditing auditor-aware-ref="auditingProvider" set-dates="true" date-time-provider-ref="dateTimeProvider"/>
</beans>
Any suggestion on how to fix it?
Tks
Add @Transactional before our function in Dao Class,this sol
来源:https://stackoverflow.com/questions/37402755/auditexception-unable-to-create-revision-because-of-non-active-transaction