161117、使用spring声明式事务抛出 identifier of an instance of
2016-12-07 15:04
856 查看
今天项目组有成员使用spring声明式事务出现下面异常,这里跟大家分享学习下。 异常信息: org.springframework.orm.hibernate3.HibernateSystemException: identifier of an instance of com.xxx.entity.Activity was altered from 33 to null; nested exception is org.hibernate.HibernateException: identifier of an instance of com.xxx.entity.Activity was altered from 33 to null 出现异常代码:(都是在service层中的一个方法里) @Service @Transactional public class GroupServiceImpl extends CoreManagerImpl<Group> implements GroupService 省略 @Override public Group updateGroup(Group group,Group old) throws Exception { Group doGroupUpdate = doGroupUpdate(group, old); List<SubGroup> subs = doSubGroupsUpdate(group.getSubGroups(), doGroupUpdate.getId()); doGroupUpdate.setSubGroups(subs); Activity activity = updateActivity(doGroupUpdate); activity.setId(null);//发生异常的原因 updateSeller(doGroupUpdate); doGroupUpdate.setActivity(activity); return doGroupUpdate; } 修复后代码: @Override public Group updateGroup(Group group,Group old) throws Exception { Group doGroupUpdate = doGroupUpdate(group, old); List<SubGroup> subs = doSubGroupsUpdate(group.getSubGroups(), doGroupUpdate.getId()); doGroupUpdate.setSubGroups(subs); Activity activity = updateActivity(doGroupUpdate); //activity.setId(null); updateSeller(doGroupUpdate); doGroupUpdate.setActivity(activity); return doGroupUpdate; } 原因分析: 使用spring声明试事务,在整个事务(里面有多个子事务)没有提交成功,就将id主键设置成了null(主键不可以为null),所以会抛出上述异常。spring声明式事务是在所有子操作都完成一起提交事务的。
相关文章推荐
- identifier of an instance of com.jh.oa.bpm.model.JhBpmFormdata was altered from 266 to 267
- Spring使用XML进行声明式的事务管理
- identifier of an instance ...... altered from ** to **
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- 错误 identifier of an instance of
- 使用反射报异常:object is not an instance of declaring class解决方案
- 使用内部类时提示No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- 使用Spring AOP 自动代理配置声明式事务
- 使用Spring 2.0 新特性实现声明式事务管理-基于Annotation
- identifier of an instance of Object is altered from 2 to 5
- 遇到错误 org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X 将int
- org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X
- 连续多次进入使用了MJRefresh的页面应用会崩 An instance 0xdb48a00 of class UITableView was deallocated while key value
- EJB3 Exception:identifier of an instance of net.model.entity.Role was altered from 2 to 0
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- identifier of an instance ... altered from num1 to num2
- 使用spring+springMVC 组合开发,声明式事务失效
- spring-使用注解配置声明式事务
- SpringMVC+Spring+Mybatis整合,使用druid连接池,声明式事务,maven配置
- Spring声明式事务之NameMatchAtttirbuteSource使用