permaculture playing cards
The moose likes Object Relational Mapping and the fly likes ManyToMany assoicate delete join table entry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ManyToMany assoicate delete join table entry" Watch "ManyToMany assoicate delete join table entry" New topic

ManyToMany assoicate delete join table entry

Johnny Cheng

Joined: Nov 05, 2009
Posts: 5
I use these two entities to create a new user and groups it associates:

On the database:
usertable (id, userId, name)
grouptable (id, description)
usergroup(userid, groupid, groupkey)

It's very satisfying to add Group to list of groups, call save method on User and watch hibernate save the usergoup togehter. However, I have a big problem of hibernate automatically deleting entry from the usergroup table automatically when even I retrieve the User after a save(User) operation.

Here is the test sequence that generation the deletion of usergroup

1. save new user
2. save new group
3. And group to list in user
4. save user
5. get user from email

While before executing step 5, usergroup with automatically removed like


A few thing i wonder;
1. userid is NOT the pk of user object.
2. The manyTomany mapping in usergroup mapped by userid and groupid

How can I stop the automatic deletion of usergroup. Usergroup is very important table and should not be deleted. Any help would be much appreciated. Thank you.
I agree. Here's the link:
subject: ManyToMany assoicate delete join table entry
jQuery in Action, 3rd edition