Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate - Deleting a parent and it's children

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there!
I need some help understanding something/getting it to work.
In a previous post (https://coderanch.com/t/217070/ORM/java/Hibernate-one-many), I was having a hard time understanding how to get one-to-many collections to work. Thanks to your help, I managed to figure it out. Now, I'm trying to figure out how to delete the collections (and then the parent).
Now. What I fiugure, is when you have a parent, with children in a one-to-many relationship, and having cascade set to "all-delete-cascade", when you delete the parent, it should cascade over and delete the children also.

But that doesn't seem to be the case. I just get a foeign key error.

So. I figure I must delete the children first! But how...

I have 2.5 classes: a Doctor class, and an Appointment class.
Doctors have appointments.

Here's the Doctor class:


...and here's the Appointment Class:


...and because I'm neurotic (or a good developer, I have a subclass called DoctorsApointment. It just creates an instance of Doctor, and it's getter and setters.

Finally, here's my code where I attempt to delete what I created:


Now... What I'm trying to do, is first delete all the appointments, then the doctor. When I run it, I still get a "MySQLIntegerityConstraintVoiletingException", which is bascially telling me I'm voilating the relationship by deleting the doctor.

Can y'all help me make sense of this?

Thanks!

Casey Kcins
[ March 21, 2007: Message edited by: Casey Kcins ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the cascade option you are looking for is not

"all-delete-cascade"

but

"all, delete-orphan"

Mark
 
Casey Kcins
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I had in there like that. I typed it wrong here.

Still doesn't work though...
[ March 23, 2007: Message edited by: Casey Kcins ]
 
What's gotten into you? Could it be this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic