HHH-15159 Orphan removal of an entity with an @ElementCollection causes a ConstraintViolationException

This commit is contained in:
Andrea Boriero 2022-05-06 10:41:51 +02:00 committed by Christian Beikov
parent 6c3d700fcc
commit 41b067e5a5
1 changed files with 17 additions and 14 deletions

View File

@ -107,7 +107,23 @@ public class ActionQueue {
private static final LinkedHashMap<Class<? extends Executable>,ListProvider<?>> EXECUTABLE_LISTS_MAP;
static {
EXECUTABLE_LISTS_MAP = CollectionHelper.linkedMapOfSize( 8 );
/*
CollectionRemoveAction actions have to be executed before OrphanRemovalAction actions, to prevent a constraint violation
when deleting an orphan Entity that contains an ElementCollection (see HHH-15159)
*/
EXECUTABLE_LISTS_MAP.put(
CollectionRemoveAction.class,
new ListProvider<CollectionRemoveAction>() {
ExecutableList<CollectionRemoveAction> get(ActionQueue instance) {
return instance.collectionRemovals;
}
ExecutableList<CollectionRemoveAction> init(ActionQueue instance) {
return instance.collectionRemovals = new ExecutableList<>(
instance.isOrderUpdatesEnabled()
);
}
}
);
EXECUTABLE_LISTS_MAP.put(
OrphanRemovalAction.class,
new ListProvider<OrphanRemovalAction>() {
@ -166,19 +182,6 @@ public class ActionQueue {
}
}
);
EXECUTABLE_LISTS_MAP.put(
CollectionRemoveAction.class,
new ListProvider<CollectionRemoveAction>() {
ExecutableList<CollectionRemoveAction> get(ActionQueue instance) {
return instance.collectionRemovals;
}
ExecutableList<CollectionRemoveAction> init(ActionQueue instance) {
return instance.collectionRemovals = new ExecutableList<>(
instance.isOrderUpdatesEnabled()
);
}
}
);
EXECUTABLE_LISTS_MAP.put(
CollectionUpdateAction.class,
new ListProvider<CollectionUpdateAction>() {