问题
I have an entity which has @OneToMany
private ownership of a collection of another entities.
That other entity has some unique constraints over different set of columns.
The problem arises when I want to update the main entity (together with changed child entities). EclipseLink does insert before delete, so sometimes, an insertion violates the constraint and throws an exception.
Is there a way to force the deletion of child entities before inserting their updated counterparts?
回答1:
I know, I'm a bit late, but anyway:
UnitOfWork uow = JpaHelper.getEntityManager(em).getUnitOfWork();
uow.setShouldPerformDeletesFirst(true);
uow.setShouldOrderUpdates(true);
But sometimes also updateBeforeInsert would be needed, no idea to force that.
来源:https://stackoverflow.com/questions/19808744/how-to-force-eclipselinks-privateowned-to-perform-delete-before-insert