Skip to content

Commit c973054

Browse files
committed
HHH-19555 improve tests
1 parent 3633346 commit c973054

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/manytoone/jointable/ManyToOneImplicitJoinTableRestrictionTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
@Jpa(annotatedClasses =
2424
{ManyToOneImplicitJoinTableRestrictionTest.X.class,
2525
ManyToOneImplicitJoinTableRestrictionTest.Y.class})
26-
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "Sybase doesn't have support for upserts")
26+
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true,
27+
reason = "Sybase doesn't have support for upserts")
2728
class ManyToOneImplicitJoinTableRestrictionTest {
2829
@JiraKey("HHH-19555") @Test
2930
void test(EntityManagerFactoryScope scope) {
@@ -47,6 +48,16 @@ void test(EntityManagerFactoryScope scope) {
4748
var id = s.createNativeQuery( "select x_id from Y_X", long.class ).getSingleResult();
4849
assertEquals( -1L, id );
4950
} );
51+
scope.inTransaction( s -> {
52+
Y y =
53+
s.createQuery( "from Y where id = ?1", Y.class )
54+
.setParameter( 1, 0L )
55+
.getSingleResult();
56+
assertEquals("Gavin", y.name);
57+
assertNull(y.x);
58+
var id = s.createNativeQuery( "select x_id from Y_X", long.class ).getSingleResult();
59+
assertEquals( -1L, id );
60+
} );
5061
scope.inTransaction( s -> {
5162
Y y = s.find( Y.class, 0L );
5263
X x = new X();
@@ -63,6 +74,16 @@ void test(EntityManagerFactoryScope scope) {
6374
var id = s.createNativeQuery( "select x_id from Y_X", long.class ).getSingleResult();
6475
assertEquals( 1L, id );
6576
} );
77+
scope.inTransaction( s -> {
78+
Y y =
79+
s.createQuery( "from Y where id = ?1", Y.class )
80+
.setParameter( 1, 0L )
81+
.getSingleResult();
82+
assertEquals("Gavin", y.name);
83+
assertNotNull(y.x);
84+
var id = s.createNativeQuery( "select x_id from Y_X", long.class ).getSingleResult();
85+
assertEquals( 1L, id );
86+
} );
6687
scope.inTransaction( s -> {
6788
Y y = s.find( Y.class, 0L );
6889
y.x = null;
@@ -75,6 +96,14 @@ void test(EntityManagerFactoryScope scope) {
7596
var id = s.createNativeQuery( "select x_id from Y_X", long.class ).getSingleResultOrNull();
7697
assertNull( id );
7798
} );
99+
scope.inTransaction( s -> {
100+
Y y =
101+
s.createQuery( "from Y where id = ?1", Y.class )
102+
.setParameter( 1, 0L )
103+
.getSingleResult();
104+
assertEquals("Gavin", y.name);
105+
assertNull(y.x);
106+
} );
78107
}
79108

80109
@Entity(name="Y")

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/manytoone/jointable/ManyToOneImplicitJoinTableTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ void test(EntityManagerFactoryScope scope) {
3838
assertNotNull(y.x);
3939
assertEquals( 1L, y.x.id );
4040
} );
41+
scope.inTransaction( s -> {
42+
Y y =
43+
s.createQuery( "from Y where id = ?1", Y.class )
44+
.setParameter( 1, 0L )
45+
.getSingleResult();
46+
assertEquals("Gavin", y.name);
47+
assertNotNull(y.x);
48+
var id = s.createNativeQuery( "select x_id from Y_X", long.class ).getSingleResult();
49+
assertEquals( 1L, id );
50+
} );
4151
scope.inTransaction( s -> {
4252
Y y = s.find( Y.class, 0L );
4353
X x = new X();
@@ -52,6 +62,16 @@ void test(EntityManagerFactoryScope scope) {
5262
assertNotNull(y.x);
5363
assertEquals( -1L, y.x.id );
5464
} );
65+
scope.inTransaction( s -> {
66+
Y y =
67+
s.createQuery( "from Y where id = ?1", Y.class )
68+
.setParameter( 1, 0L )
69+
.getSingleResult();
70+
assertEquals("Gavin", y.name);
71+
assertNotNull(y.x);
72+
var id = s.createNativeQuery( "select x_id from Y_X", long.class ).getSingleResult();
73+
assertEquals( -1L, id );
74+
} );
5575
scope.inTransaction( s -> {
5676
Y y = s.find( Y.class, 0L );
5777
y.x = null;
@@ -62,6 +82,14 @@ void test(EntityManagerFactoryScope scope) {
6282
assertEquals("Gavin", y.name);
6383
assertNull(y.x);
6484
} );
85+
scope.inTransaction( s -> {
86+
Y y =
87+
s.createQuery( "from Y where id = ?1", Y.class )
88+
.setParameter( 1, 0L )
89+
.getSingleResult();
90+
assertEquals("Gavin", y.name);
91+
assertNull(y.x);
92+
} );
6593
}
6694

6795
@Entity(name="Y")

0 commit comments

Comments
 (0)