Hi all,
I was having problems getting my @ManyToMany association collections to save their associations inside of the join table. I was wondering if anyone had seen this problem before? I have seen that you can use the @Persister and make a customer persister but I wanted to see if there was a way I could save the associations of user and groups inside of my association table without having to make a custom persister.
Database
Code:
tblUser
userID
tblGroup
groupID
tblUserHasGroup
userID
groupID
User
Code:
@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH},targetEntity=Group.class)
@JoinTable(
name="tblUserHasGroup",
joinColumns=@JoinColumn(name="userID", referencedColumnName="id"),
inverseJoinColumns=@JoinColumn(name="groupID", referencedColumnName="id")
)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.PERSIST})
public Set<Permission> getGroups()
.........
Group
Code:
@ManyToMany(mappedBy = "groups", targetEntity=User.class, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})