This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes Orphan delete doesn't seem to be working properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Orphan delete doesn Watch "Orphan delete doesn New topic
Author

Orphan delete doesn't seem to be working properly

Eric Nielsen
Ranch Hand

Joined: Dec 14, 2004
Posts: 194
I'm trying to set up an assocition using the hibernate "delete orphan" option. I believe I have all the annotations correct after cross referencing the hibernate book. However after removing the item from the collection, Hibernate is attempting to set the foreign key to null. Which violates a database constraint. Hibernate has been told about the not-null constraint...

Here's my code:

Competition.java

Event.java


Consuming code (In actuality its a Struts 2 action using preparable and custom type converters, here I've localized all the relevant code and have tests that it gives the same error as my actual architecture. But felt I had to explain the combination of repositoty and direct entityManager access...)


Error:


I had thought that the combination of the DELETE_ORPHAN on the owning side of the association and the nullable=false on the owned side would have prevented hibernate from attempting that update. What am I doing wrong?
Eric Nielsen
Ranch Hand

Joined: Dec 14, 2004
Posts: 194
I am really stumped on this. Please, does anyone have any idea what I'm doing wrong? Or what other information is needed to help diagnose the problem?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Orphan delete doesn't seem to be working properly