I have four classes [User, Group, Role and Application] that have many to many relationships between them.
I have followed the reference manual and made one side of each relationship the owner (with @JoinTable) and one side the non-owning side (with @ManyToMany(mappedBy="xxx").
There are then three relationships between these classes which I explain like this:
User(owner), Group [USER_GROUP association table]
Group(owner), Role [GROUP_ROLE association table]
Role(owner), Application [ROLE_APPLICATION association table]
When I attempt to delete a Group 'getHibernateTemplate.delete(group);' it appears to remove the associations in the GROUP_ROLE table however does not remove the associations in the USER_GROUP table as I am expecting it to. I am having to iterate through the group.getUsers SET and remove the group manually from each User.
When you have a class mapping between two ManyToMany relationships how are you supposed to set up the annotations. I have searched far and wide and find no examples of same. Can hibernate manage the two association tables automatically and if so how does that work?
Your help much appreciated,
Luke.
|