This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Bi-directional many-to-many mapping question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Bi-directional many-to-many mapping question" Watch "Bi-directional many-to-many mapping question" New topic

Bi-directional many-to-many mapping question

Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228

I have an many-to-many relationship mapped with annotations
as below:

I am updating the UserGroup by doing:

I am getting this exception:

If i remove cascade=CascadeType.ALL from Group entity i
don't get any exception but i want to keep cascade in Group entity.
Is there anything i need to do to get rid of this exception or I should
remove cascade in Group entity?

Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
Could anyone please let me know
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968


I think this means the primary key of the object you are trying to delete is null. Can you verify this by doing some logging? So, if the primary key is null and you ask Hibernate to delete it, it won't know what row in the underlying database to delete.

-Cameron McKenzie
wood burning stoves
subject: Bi-directional many-to-many mapping question
Similar Threads
JPA: Cascade delete for join tables with composite key
detached entity passed to persist
Outer join between 3 entities in HQL
using 2 @OnetoMany annoations in one Entity Class
Orphan delete doesn't seem to be working properly