1+ /*
2+ * SPDX-License-Identifier: LGPL-2.1-or-later
3+ * Copyright Red Hat Inc. and Hibernate Authors
4+ */
15package org .hibernate .orm .test .flush ;
26
3- import org .hibernate .testing .jdbc .SQLStatementInspector ;
47import org .hibernate .testing .orm .junit .DomainModel ;
58import org .hibernate .testing .orm .junit .SessionFactory ;
69import org .hibernate .testing .orm .junit .SessionFactoryScope ;
2225 AutoFlushOnUpdateQueryTest .Fruit .class ,
2326 }
2427)
25- @ SessionFactory (
26- statementInspectorClass = SQLStatementInspector .class
27- )
28+ @ SessionFactory
2829public class AutoFlushOnUpdateQueryTest {
2930
3031 public static final String FRUIT_NAME = "Apple" ;
@@ -50,8 +51,6 @@ public void tearDown(SessionFactoryScope scope) {
5051
5152 @ Test
5253 public void testFlushIsExecuted (SessionFactoryScope scope ) {
53- SQLStatementInspector statementInspector = scope .getStatementInspector ( SQLStatementInspector .class );
54- statementInspector .clear ();
5554 scope .inTransaction (
5655 session -> {
5756 Fruit fruit = session
@@ -81,6 +80,37 @@ public void testFlushIsExecuted(SessionFactoryScope scope) {
8180 );
8281 }
8382
83+ @ Test
84+ public void testFlushIsExecuted2 (SessionFactoryScope scope ) {
85+ scope .inTransaction (
86+ session -> {
87+ Fruit fruit = session
88+ .createQuery (
89+ "select f from Fruit f where f.name = :name" ,
90+ Fruit .class
91+ ).setParameter ( "name" , FRUIT_NAME ).getSingleResult ();
92+
93+ FruitLogEntry logEntry = new FruitLogEntry ( fruit , "foo" );
94+ session .persist ( logEntry );
95+
96+ session .createMutationQuery ( "update Fruit f set f.logEntry.id = :logEntryId where f.id = :fruitId" )
97+ .setParameter ( "logEntryId" , logEntry .getId () )
98+ .setParameter ( "fruitId" , fruit .getId () ).executeUpdate ();
99+ }
100+ );
101+
102+ scope .inTransaction (
103+ session -> {
104+ Fruit fruit = session
105+ .createQuery (
106+ "select f from Fruit f where f.name = :name" ,
107+ Fruit .class
108+ ).setParameter ( "name" , FRUIT_NAME ).getSingleResult ();
109+ assertThat ( fruit .getLogEntry () ).isNotNull ();
110+ }
111+ );
112+ }
113+
84114 @ Entity (name = "Fruit" )
85115 public static class Fruit {
86116
0 commit comments