Skip to content

Commit

Permalink
HHH-18563 Add test using foreign key property
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Sep 9, 2024
1 parent adee718 commit 01acc3c
Showing 1 changed file with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hibernate.orm.test.flush;

import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
Expand All @@ -22,9 +21,7 @@
AutoFlushOnUpdateQueryTest.Fruit.class,
}
)
@SessionFactory(
statementInspectorClass = SQLStatementInspector.class
)
@SessionFactory
public class AutoFlushOnUpdateQueryTest {

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

@Test
public void testFlushIsExecuted(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = scope.getStatementInspector( SQLStatementInspector.class );
statementInspector.clear();
scope.inTransaction(
session -> {
Fruit fruit = session
Expand Down Expand Up @@ -81,6 +76,37 @@ public void testFlushIsExecuted(SessionFactoryScope scope) {
);
}

@Test
public void testFlushIsExecuted2(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Fruit fruit = session
.createQuery(
"select f from Fruit f where f.name = :name",
Fruit.class
).setParameter( "name", FRUIT_NAME ).getSingleResult();

FruitLogEntry logEntry = new FruitLogEntry( fruit, "foo" );
session.persist( logEntry );

session.createMutationQuery( "update Fruit f set f.logEntry.id = :logEntryId where f.id = :fruitId" )
.setParameter( "logEntryId", logEntry.getId() )
.setParameter( "fruitId", fruit.getId() ).executeUpdate();
}
);

scope.inTransaction(
session -> {
Fruit fruit = session
.createQuery(
"select f from Fruit f where f.name = :name",
Fruit.class
).setParameter( "name", FRUIT_NAME ).getSingleResult();
assertThat( fruit.getLogEntry() ).isNotNull();
}
);
}

@Entity(name = "Fruit")
public static class Fruit {

Expand Down

0 comments on commit 01acc3c

Please sign in to comment.