Hey,
I tried to get an very easy feature to run, but i was supprised
how many possibilities i found, and that at least only one worked.
A ChildClass has an ManyToOne reference to a ParantClass. When
the parent will be deleted, i want every child deleted as well. Thats
all. One possibility is of course, i delete all children myself an
delete than the parent. But i think Hibernate should handle this.
Code:
@Entity
public class Child {
private Parent parent;
@ManyToOne
public Parent getParent() {...}
public void setParent(..){..}
}
@Entity
public class Parent {
private anything...
}
So there ist the possibility to use the JPI stuff like. In
class Child I did the following:
Code:
@ManyToOne (cascade = CascadeType.ALL)
public Parent getParent() {...}
Of course I tried CascateType.REMOVE and things like
that.
Does not work. OK, next try: This time i use the
Hibernate stuff.
Code:
@Cascade( value = CascadeType.ALL)
public Parent getParent() {...}
Of course I tried this DELETE_ORPHAN
Does not work. Ok, next Try: This time i use
another thing i found in the documentation:
Code:
@OnDelete(action = OnDeleteAction.CASCADE)
public Parent getParent() {...}
Does not work. Ok, next Try: If i say it is a unidirectional
relation, that means that i have to change the parent class.
Code:
@Entity
public class Parent {
private List<Child> children = new ArrayList...
@OneToMany(cascade={ CascadeType.ALL},
fetch = FetchType.LAZY,
mappedBy = "parent")
public List<Child> getChildren() {...}
public void setChildren(...)
}
This works fine, but this is not what i wanted. Are the features
not implemented? Any ideas ? What did i wrong?