onetomany级联删除异常

错误:

Caused by: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)

在service业务层添加事务注解@Transactional

	//删除用户组
	public boolean delUserGroup(GroupVo groupVo){
		String groupname = groupVo.getGroupname();
		SystemGroup group = null;
		if(groupname!=null){
			group = systemGroupDao.getSystemGroupByName(groupname);
		}
		if(group == null){
			return false;
		}
//		systemGroupDao.delSystemGroupActionByGroupName(group);
		group.delGroupAction();
		systemGroupDao.delete(group);
		return true;
	}

 事务开始到结束 都是同一session处理,导致查询出来的语句的状态还在关联session中[associations]

 必须删除事务标签

 

另一种情况

class:ActionRole

	@ManyToOne
	@JoinColumn(name = "actionid")
	private SystemAction action;
	
	@ManyToOne
	@JoinColumn(name = "roleid")
	private SystemRole role;

 class:SystemRole 

@OneToMany(mappedBy = "role", cascade = CascadeType.ALL,fetch=FetchType.EAGER)
private Set<SystemGroupAction> groupActions;

 

role.getGroupActions().clear();

 

systemGroupDao.delSystemRole(role);

你可能感兴趣的:(net)