Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - Deleting a parent and it's children

 
Casey Kcins
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
I need some help understanding something/getting it to work.
In a previous post (http://www.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 ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic