Two Laptop Bag
The moose likes Object Relational Mapping and the fly likes Simple But Crazy Cascade Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Simple But Crazy Cascade Problem" Watch "Simple But Crazy Cascade Problem" New topic

Simple But Crazy Cascade Problem

Gokcen Guner

Joined: May 23, 2009
Posts: 9
Although I'm using javax.persistence.CascadeType.ALL, org.hibernate.annotations.CascadeType.ALL, and OnDeleteAction.CASCADE I couldn't manage to delete parent row.
My code is like that:

I have one base class Person and 2 inherited classes Doctor and Patient. One doctor can have one or more patients but a patient is related to only one doctor. That is so simple. But for hours I couldn't delete a doctor that have patients referencing on it. I want the patients to be deleted when their doctor is deleted.
The exception trace is:

What I need to do? I'm using all deletion cascades, orphan removal etc.
Please tell me the problem. It must work, isn't it?


I've looked at the generated schema:

with the mapping for these annotation configuration:

As you see hibernate is aware of foreign keys PERSON_USER_FK and PATIENT_DOCTOR_FK but doesn't generate Cascade statements. I will go mad please help me.
I agree. Here's the link:
subject: Simple But Crazy Cascade Problem
It's not a secret anymore!