From 20d26a012644e7ca3810a1bcdef8286054f4f0c9 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 5 Jun 2024 01:42:47 +0200 Subject: [PATCH] HHH-9568/HHH-9571 fix orphanRemoval in JPA bootstrap Signed-off-by: Gavin King --- .../main/java/org/hibernate/engine/spi/CascadeStyles.java | 5 +++-- .../jpa/orphan/onetomany/DeleteOneToManyOrphansTest.java | 7 +++---- .../java/org/hibernate/orm/test/jpa/orphan/onetoone/A.java | 2 +- .../java/org/hibernate/orm/test/jpa/orphan/onetoone/B.java | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyles.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyles.java index bca4f02093..4d6e558739 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyles.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyles.java @@ -197,7 +197,8 @@ public final class CascadeStyles { @Override public boolean doCascade(CascadingAction action) { return action == CascadingActions.DELETE - || action == CascadingActions.SAVE_UPDATE //WHAT?? + || action == CascadingActions.SAVE_UPDATE + || action == CascadingActions.PERSIST_ON_FLUSH || action == CascadingActions.CHECK_ON_FLUSH; } @@ -307,7 +308,7 @@ public final class CascadeStyles { @Override public boolean doCascade(CascadingAction action) { if ( action == CascadingActions.CHECK_ON_FLUSH ) { - return !doCascade( CascadingActions.PERSIST_ON_FLUSH ); + return !reallyDoCascade( CascadingActions.PERSIST_ON_FLUSH ); } for ( CascadeStyle style : styles ) { if ( style.doCascade( action ) ) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetomany/DeleteOneToManyOrphansTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetomany/DeleteOneToManyOrphansTest.java index 6b721ed1a5..afc9c843d6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetomany/DeleteOneToManyOrphansTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetomany/DeleteOneToManyOrphansTest.java @@ -10,7 +10,6 @@ import java.util.List; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; -import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.Jpa; import org.junit.jupiter.api.AfterEach; @@ -56,7 +55,7 @@ public class DeleteOneToManyOrphansTest { @Test @TestForIssue( jiraKey = "HHH-9568") - @FailureExpected( jiraKey = "HHH-9568" ) +// @FailureExpected( jiraKey = "HHH-9568" ) public void testOrphanedWhileManaged(EntityManagerFactoryScope scope) { Long productId = scope.fromTransaction( entityManager -> { @@ -85,7 +84,7 @@ public class DeleteOneToManyOrphansTest { @Test @TestForIssue( jiraKey = "HHH-9568") - @FailureExpected( jiraKey = "HHH-9568" ) +// @FailureExpected( jiraKey = "HHH-9568" ) public void testOrphanedWhileManagedMergeOwner(EntityManagerFactoryScope scope) { Long productId = scope.fromTransaction( entityManager -> { @@ -115,7 +114,7 @@ public class DeleteOneToManyOrphansTest { @Test @TestForIssue( jiraKey = "HHH-9568") - @FailureExpected( jiraKey = "HHH-9568" ) +// @FailureExpected( jiraKey = "HHH-9568" ) public void testReplacedWhileManaged(EntityManagerFactoryScope scope) { Long featureNewId = scope.fromTransaction( entityManager -> { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/A.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/A.java index 317e1f2917..45c24b346c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/A.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/A.java @@ -30,7 +30,7 @@ public class A implements Serializable { this.id = id; } - @OneToOne(targetEntity=B.class, mappedBy="a", orphanRemoval = true) + @OneToOne(mappedBy = "a", orphanRemoval = true) public B getB() { return b; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/B.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/B.java index 0f9194b537..6555a824b9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/B.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/B.java @@ -32,8 +32,8 @@ public class B implements Serializable { this.id = id; } - @OneToOne(targetEntity=A.class, cascade=CascadeType.ALL,optional = true, orphanRemoval = true) - @JoinColumn(name="FK_FOR_B") + @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "FK_FOR_B") public A getA() { return a; }