java - NonUniqueObjectException on saving joined tables -
I have two related tables in a many to many relationship: Role
and allow
. The join table is RolePermission
.
role
is a list of permission to object. It looks like:
Private set & lt; Permission & gt; Permissions; @ManyToMany (speed = FetchType.EAGER, cascade = {CascadeType.ALL}) @JoinTable (name = "permission_role", joinColumns = @JoinColumn (name = "ROLE_ID"), inverseJoinColumns = @JoinColumn (name = "permission_id")) Public set & lt; ObjectPermission & gt; GetObjectPermissions () {Return Object Submissions; .}
Adding a certain time I want to add permissions for a role:
role.getObjectPermissions () (permission); RoleDAO.saveOrUpdate (role);
Both roles and permissions are already present in DB, each in its table to add a record to the connection table, that will indicate both the role and the permissions:
role.addObjectEntryPermissionRole (permission); RoleDAO.saveOrUpdate (role);
The problem is that it seems that this permission is trying to save themselves! Then throws this error:
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already connected to the session: [com.XXX.model.Permission # 11]
Can anyone tell me what is the problem? what I have done?
I had the same problem, remove cascade = {CascadeType.ALL}
Having solved this issue
Comments
Post a Comment