Hi
I run the following code (in a transaction) for a collection with all-delete-orphan:
Code:
parent.getChildren().clear();
parent.add(child1);
parent.add(child2);
parent.add(child3);
Code:
class Parent{
Integer id;
Set children;
...
}
class Child{
Integer id;
String someUniqueProp;
...
}
on Child.someUniqueProp I have a DB unique constrain
also the property is mapped as unique='true' in the mapping file
before the call to parent.getChildren().clear() the parent contained a chiled with someUniqueProp="X" (persistent)
child1 that is added after the call to clear, also contains someUniqueProp="X"
when I run the above code (psaudo code) I get an exception (unique constrain vilation)
does hibernate first add the new children and only then delete orphans?
to check it I tried:
Code:
parent.getChildren().clear();
// force delete of orphans
session.flush()
// continue adding children
parent.add(child1);
parent.add(child2);
parent.add(child3);
now the unique constrain violation doesn't happen
since I will get this object as a detached object with no ability to call flush after the call to clear(), is there any other way to make sure all-delete-orphan will first delete orphans and only then add the new children?
I can force uniqueness in code but this is unacceptable by the design
any other way to have a detached object with all-delete-orphan and a unique constrain?
Thanks
Ehrann