-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Depth of cascade for delete on a external jointable
PostPosted: Mon Mar 17, 2008 11:34 am 
Newbie

Joined: Tue Jan 29, 2008 1:28 pm
Posts: 3
Lets pretend we have three tables and two classes (not the case but a close example)
Code:
SODA
SODAID (PK)
SODANAME

DRINKER
DRINKERID (PK)
DRINKERNAME

DRINKS
DRINKERID (FK)
SODAID (FK)


These classes have all the appropriate annotations. I am only including the annotations that are involved in the question.
Code:
public class Soda{
long id;
String name;
}

public class Drinker{
long id;
String name;
List<Soda> drinks;

@OneToMany(targetEntity=Soda.class)
@JoinTable(name = "DRINKS", joinColumns = { @JoinColumn(name = "DRINKERID") }, inverseJoinColumns = { @JoinColumn(name = "SODAID") })
List<Soda> getDrinks(){
  return drinks;
}
}


The question is when I delete a drinker how far does hibernate cascade down? Obviously a cascade annotation is required to enable that but what I am wondering is does hibernate delete my drinker and linking records in my drinks table or does it also delete my linked soda rows from the Soda table.

Deleting soda rows would obviously complicate things because if I delete a drinker it would end up cascading to the point of deleting any linking rows from Drinks that match a soda id that just got deleted.

Also what gets deleted if I execute a delete on a individual soda object from getDrinks?

_________________
http://mindjunk.org


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.