Hi all :)
I have a field annotated @Cascade (value=DELETE_ORPHAN).
It works in our application for a long time, but now we've discovered a situation in which we need to move an object (the child in the mapping) to other parent. Suppose we have:
Code:
@Entity
public class Parent{
@OneToMany
@Cascade (value=DELETE_ORPHAN)
private List children;
...
}
And now we want to do (if parent1 and parent2 are instances of Parent):
Code:
parent1.getChildren().add(parent2.getChildren().get(0)
Is it possible to have a delete_orphan behavior, but in this "more general"way. That orphans which do not have any parent are deleted?
If not:
a workaround would be if I could say hibernate, that in application 1 it should use DELETE_ORPHAN, but in app2 (which updates some database data) it should not use cascade. Is that possible?
I'll be grateful for any help :)
Greets
Michal
PS write if sth is not clear :)