Skip to content

Commit 01acc3c

Browse files
committed
HHH-18563 Add test using foreign key property
1 parent adee718 commit 01acc3c

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/flush/AutoFlushOnUpdateQueryTest.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.hibernate.orm.test.flush;
22

3-
import org.hibernate.testing.jdbc.SQLStatementInspector;
43
import org.hibernate.testing.orm.junit.DomainModel;
54
import org.hibernate.testing.orm.junit.SessionFactory;
65
import org.hibernate.testing.orm.junit.SessionFactoryScope;
@@ -22,9 +21,7 @@
2221
AutoFlushOnUpdateQueryTest.Fruit.class,
2322
}
2423
)
25-
@SessionFactory(
26-
statementInspectorClass = SQLStatementInspector.class
27-
)
24+
@SessionFactory
2825
public class AutoFlushOnUpdateQueryTest {
2926

3027
public static final String FRUIT_NAME = "Apple";
@@ -50,8 +47,6 @@ public void tearDown(SessionFactoryScope scope) {
5047

5148
@Test
5249
public void testFlushIsExecuted(SessionFactoryScope scope) {
53-
SQLStatementInspector statementInspector = scope.getStatementInspector( SQLStatementInspector.class );
54-
statementInspector.clear();
5550
scope.inTransaction(
5651
session -> {
5752
Fruit fruit = session
@@ -81,6 +76,37 @@ public void testFlushIsExecuted(SessionFactoryScope scope) {
8176
);
8277
}
8378

79+
@Test
80+
public void testFlushIsExecuted2(SessionFactoryScope scope) {
81+
scope.inTransaction(
82+
session -> {
83+
Fruit fruit = session
84+
.createQuery(
85+
"select f from Fruit f where f.name = :name",
86+
Fruit.class
87+
).setParameter( "name", FRUIT_NAME ).getSingleResult();
88+
89+
FruitLogEntry logEntry = new FruitLogEntry( fruit, "foo" );
90+
session.persist( logEntry );
91+
92+
session.createMutationQuery( "update Fruit f set f.logEntry.id = :logEntryId where f.id = :fruitId" )
93+
.setParameter( "logEntryId", logEntry.getId() )
94+
.setParameter( "fruitId", fruit.getId() ).executeUpdate();
95+
}
96+
);
97+
98+
scope.inTransaction(
99+
session -> {
100+
Fruit fruit = session
101+
.createQuery(
102+
"select f from Fruit f where f.name = :name",
103+
Fruit.class
104+
).setParameter( "name", FRUIT_NAME ).getSingleResult();
105+
assertThat( fruit.getLogEntry() ).isNotNull();
106+
}
107+
);
108+
}
109+
84110
@Entity(name = "Fruit")
85111
public static class Fruit {
86112

0 commit comments

Comments
 (0)