oneToMany 修改many端属性saveupdate

ONE端

	@OneToMany(mappedBy = "role", cascade = CascadeType.ALL,fetch=FetchType.EAGER,orphanRemoval=true)
	@OrderBy(value = "action ASC")
	private Set<SystemGroupAction> groupActions;

 Many端

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

 saveUpdate

public boolean saveRole(RoleVo roleVo){
		SystemRole role = systemGroupDao.getSystemRoleByName(roleVo.getRolename());
		if(role == null){
			role = new SystemRole();
			role.setCreatetime(new Date());
			role.setRolename(roleVo.getRolename());
		}
		role.setRoledesc(roleVo.getRoledesc());
		List<ActionVo> list = roleVo.getActions();
		SystemGroupAction roleaction = null;
		for(ActionVo vo :list){
			roleaction = systemGroupDao.getAssociationByRoleAction(roleVo.getRolename(),vo.getAction());
			if(roleaction!=null){
				role.getGroupActions().remove(roleaction);
			}
			roleaction = new SystemGroupAction();
			SystemAction action = systemGroupDao.getSystemActionByAction(vo.getAction());
			roleaction.setAction(action);
			roleaction.setRole(role);
			roleaction.setActive(vo.isActive());
			role.addGroupAction(roleaction);
		}
		systemGroupDao.saveSystemRole(role);
		return true;
	}

 set集合先要删除,在添加

你可能感兴趣的:(update)