File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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!