This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt 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 Introducing JavaFX 8 Programming this week in the JavaFX 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
I agree. Here's the link:
subject: Bi-directional many-to-many mapping question
It's not a secret anymore!