| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1177 人关注过本帖
标题:delaying identity-insert due to no transaction in progress
取消只看楼主 加入收藏
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
结帖率:40%
收藏
 问题点数:0 回复次数:3 
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>
搜索更多相关主题的帖子: opened color 信息 
2014-06-09 09:40
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
最新情况说明:
hibernate版本为:hibernate3.6.jar、spring为3.0.5。
如果从前台页面点击进入,加上过滤器opensessioninview就可以插入数据(事务可以加上)。
如果将过滤器opensessioninview删除,则不能插入数据(事务不可以加上)。
我后台的调度是quartz直接调用service,不可能走过滤器,当然不能插入了。请问还有什么好的解决办法吗(不升级jar包的情况下)?
--------------------------------------------------------------------------------
但是在另外一个项目里面
hibernate版本为:hibernate-core-4.1.7.Final.jar、spring为3.1.1。
过滤器opensessioninview加上和去掉,都可以插入数据(事务均加上)。

大家一起努力,共同打造未来!!
2014-06-09 11:00
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
在没有opensessioninview的情况下:
关键日志为:delaying identity-insert due to no transaction in progress
在有opensessioninview的情况下:
关键日志为:Exposing Hibernate transaction as JDBC transaction
executing identity-insert immediately

大家一起努力,共同打造未来!!
2014-06-09 11:50
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
因为是老项目,定义了两个
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
去掉一个就OK了。

大家一起努力,共同打造未来!!
2014-06-09 13:16
快速回复:delaying identity-insert due to no transaction in progress
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055514 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved