I have these entities
class Foo{
Set bars;
}
class Bar{
Foo parent;
String localIdentifier;
}
With this mapping (sorry,
I guess there is no alternative to flushing
From here:
Hibernate is violating a unique constraint!
Hibernate isn't quite as clever with unique constraints as it is with foreign keys. Sometimes you might need to give a little hint.
A unique constraint violation could occur if two objects are both being updated, one is "releasing" a value and the other is "obtaining" the same value. A workaround is to flush() the session manually after updating the first object and before updating the second.
(This kind of problem occurs rarely in practice.)