11package org .hibernate .orm .test .flush ;
22
3- import org .hibernate .testing .jdbc .SQLStatementInspector ;
43import org .hibernate .testing .orm .junit .DomainModel ;
54import org .hibernate .testing .orm .junit .SessionFactory ;
65import org .hibernate .testing .orm .junit .SessionFactoryScope ;
2221 AutoFlushOnUpdateQueryTest .Fruit .class ,
2322 }
2423)
25- @ SessionFactory (
26- statementInspectorClass = SQLStatementInspector .class
27- )
24+ @ SessionFactory
2825public 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