delaying identity-insert due to no transaction in progress
使用jpa时,通过后台调度,事务执行失败(但是通过前端页面点击则执行成功。)。报错信息为:- Opening JPA EntityManager
2014-06-06 13:27:04[refreshTaskQueueScheduleFactory_Worker-3][DEBUG]org.hibernate.impl.SessionImpl|<init>|265--> opened session at timestamp: 14020324240
- Registering transaction synchronization for JPA EntityManager
2014-06-06 13:27:04[refreshTaskQueueScheduleFactory_Worker-3][DEBUG]org.hibernate.event.def.AbstractSaveEventListener|performSaveOrReplicate|326--> delaying identity-insert due to no transaction in progress
- Closing JPA EntityManager
- Initiating transaction commit
- Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@e21817]
2014-06-06 13:27:04[refreshTaskQueueScheduleFactory_Worker-3][DEBUG]org.hibernate.transaction.JDBCTransaction|commit|130--> commit
2014-06-06 13:27:04[refreshTaskQueueScheduleFactory_Worker-3][DEBUG]org.hibernate.transaction.JDBCTransaction|toggleAutoCommit|223--> re-enabling autocommit
2014-06-06 13:27:04[refreshTaskQueueScheduleFactory_Worker-3][DEBUG]org.hibernate.transaction.JDBCTransaction|commit|143--> committed JDBC Connection
2014-06-06 13:27:04[refreshTaskQueueScheduleFactory_Worker-3][DEBUG]org.hibernate.jdbc.ConnectionManager|afterTransaction|325--> transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
- Closing Hibernate Session [org.hibernate.impl.SessionImpl@e21817] after transaction
- Closing Hibernate Session
2014-06-06 13:27:04[refreshTaskQueueScheduleFactory_Worker-3][DEBUG]org.hibernate.jdbc.ConnectionManager|closeConnection|464--> releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
- trace com.mchange.v2.resourcepool.BasicResourcePool@137008a [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@a2f9e6)
2014-06-06 13:27:04[refreshTaskQueueScheduleFactory_Worker-3][DEBUG]org.hibernate.jdbc.ConnectionManager|afterTransaction|325--> transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
事务配置如下:
<!-- default transaction control -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven />
<tx:advice id="tx-Advice">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="query*" propagation="REQUIRED" read-only="true" />
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="save*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="create*" propagation="REQUIRED" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<tx:advice id="tx-log">
<tx:attributes>
<tx:method name="save" propagation="REQUIRED" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="false" >
<aop:advisor advice-ref="tx-log" pointcut="execution(* com.itcast.logging.trace..*TraceDao*.*(..))"/>
</aop:config>
<aop:config proxy-target-class="false" >
<aop:advisor advice-ref="tx-Advice" pointcut="execution(* com.itcast..service..*Service*.*(..))" />
</aop:config>