Skip to content

Commit 0867f68

Browse files
committed
HHH-19565 stricter test for fix to bug
1 parent e09e3ae commit 0867f68

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/where/annotations/ManyToOneRestrictionTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
import jakarta.persistence.Table;
1212
import org.hibernate.annotations.SQLRestriction;
1313
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
14+
import org.hibernate.testing.orm.junit.JiraKey;
1415
import org.hibernate.testing.orm.junit.Jpa;
1516
import org.junit.jupiter.api.Test;
1617

18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1719
import static org.junit.jupiter.api.Assertions.assertNotNull;
18-
import static org.junit.jupiter.api.AssertionsKt.assertNull;
1920

2021
@Jpa(annotatedClasses = {ManyToOneRestrictionTest.X.class, ManyToOneRestrictionTest.Y.class})
2122
class ManyToOneRestrictionTest {
23+
@JiraKey("HHH-19565")
2224
@Test void test(EntityManagerFactoryScope scope) {
2325
scope.inTransaction(em -> {
2426
Y y = new Y();
@@ -28,24 +30,22 @@ class ManyToOneRestrictionTest {
2830
em.persist(x);
2931
em.persist(y);
3032
});
33+
// @SQLRestrictions should not be applied to
34+
// foreign key associations, or the FK will
35+
// be set to null when the entity is updated,
36+
// leading to data loss
3137
scope.inTransaction(em -> {
3238
Y y = em.find(Y.class, 0L);
33-
assertNull(y.x);
34-
var fk =
35-
em.createNativeQuery( "select xx from YY", long.class )
36-
.getSingleResultOrNull();
37-
assertNotNull(fk);
39+
assertNotNull(y.x);
40+
assertEquals(-1, y.x.id);
3841
y.name = "hello";
3942
});
4043
scope.inTransaction(em -> {
4144
Y y = em.find(Y.class, 0L);
42-
assertNull(y.x);
43-
var fk =
44-
em.createNativeQuery( "select xx from YY", long.class )
45-
.getSingleResultOrNull();
46-
assertNotNull(fk);
45+
assertNotNull(y.x);
46+
assertEquals(-1, y.x.id);
47+
assertEquals("hello", y.name);
4748
});
48-
4949
}
5050

5151
@Entity

0 commit comments

Comments
 (0)