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?