Skip to content

Commit 41b067e

Browse files
dreab8beikov
authored andcommitted
HHH-15159 Orphan removal of an entity with an @ElementCollection causes a ConstraintViolationException
1 parent 6c3d700 commit 41b067e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,23 @@ public class ActionQueue {
107107
private static final LinkedHashMap<Class<? extends Executable>,ListProvider<?>> EXECUTABLE_LISTS_MAP;
108108
static {
109109
EXECUTABLE_LISTS_MAP = CollectionHelper.linkedMapOfSize( 8 );
110-
110+
/*
111+
CollectionRemoveAction actions have to be executed before OrphanRemovalAction actions, to prevent a constraint violation
112+
when deleting an orphan Entity that contains an ElementCollection (see HHH-15159)
113+
*/
114+
EXECUTABLE_LISTS_MAP.put(
115+
CollectionRemoveAction.class,
116+
new ListProvider<CollectionRemoveAction>() {
117+
ExecutableList<CollectionRemoveAction> get(ActionQueue instance) {
118+
return instance.collectionRemovals;
119+
}
120+
ExecutableList<CollectionRemoveAction> init(ActionQueue instance) {
121+
return instance.collectionRemovals = new ExecutableList<>(
122+
instance.isOrderUpdatesEnabled()
123+
);
124+
}
125+
}
126+
);
111127
EXECUTABLE_LISTS_MAP.put(
112128
OrphanRemovalAction.class,
113129
new ListProvider<OrphanRemovalAction>() {
@@ -166,19 +182,6 @@ ExecutableList<QueuedOperationCollectionAction> init(ActionQueue instance) {
166182
}
167183
}
168184
);
169-
EXECUTABLE_LISTS_MAP.put(
170-
CollectionRemoveAction.class,
171-
new ListProvider<CollectionRemoveAction>() {
172-
ExecutableList<CollectionRemoveAction> get(ActionQueue instance) {
173-
return instance.collectionRemovals;
174-
}
175-
ExecutableList<CollectionRemoveAction> init(ActionQueue instance) {
176-
return instance.collectionRemovals = new ExecutableList<>(
177-
instance.isOrderUpdatesEnabled()
178-
);
179-
}
180-
}
181-
);
182185
EXECUTABLE_LISTS_MAP.put(
183186
CollectionUpdateAction.class,
184187
new ListProvider<CollectionUpdateAction>() {

0 commit comments

Comments
 (0)