AuditException:由于非活动事务而无法创建修订

时间:2016-05-24 00:46:52

标签: java hibernate hibernate-envers

我一直在更新我的应用程序上的框架,现在我正在尝试使用JPA配置hibernate envers以审核某些域。

审核失败时,常规持久性正常工作

我有这个错误

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)
    ....

我的配置是:

  <!--  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>

有关如何修复它的任何建议吗?

韩国社交协会

1 个答案:

答案 0 :(得分:-1)

在我们的Dao Class函数之前添加@Transactional,这个sol