HHH-16759 Added tests for transient and persistent entities

This commit is contained in:
Cedomir Igaly 2023-06-17 12:58:39 +02:00 committed by Christian Beikov
parent 75f3ad9651
commit 24467aa86e
1 changed files with 34 additions and 1 deletions

View File

@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class MergeRecordPropertyTestCase { public class MergeRecordPropertyTestCase {
@Test @Test
public void merge(SessionFactoryScope scope) { public void mergeDetached(SessionFactoryScope scope) {
scope.inTransaction( scope.inTransaction(
session -> session.persist( new MyEntity( 1L, new MyRecord( "test", "abc" ) ) ) session -> session.persist( new MyEntity( 1L, new MyRecord( "test", "abc" ) ) )
); );
@ -37,6 +37,39 @@ public class MergeRecordPropertyTestCase {
); );
} }
@Test
public void mergeTransient(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.merge( new MyEntity( 2L, new MyRecord( "test", "xyz" ) ) )
);
scope.inSession(
session -> {
final MyEntity entity = session.find( MyEntity.class, 2L );
assertEquals( "test", entity.record.name );
assertEquals( "xyz", entity.record.description );
}
);
}
@Test
public void mergePersistent(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
final MyEntity entity = new MyEntity( 3L, new MyRecord( "test", "efg" ) );
session.persist( entity );
entity.setRecord( new MyRecord( "test", "h" ) );
session.merge( entity );
}
);
scope.inSession(
session -> {
final MyEntity entity = session.find( MyEntity.class, 3L );
assertEquals( "test", entity.record.name );
assertEquals( "h", entity.record.description );
}
);
}
@Entity(name = "MyEntity") @Entity(name = "MyEntity")
public static class MyEntity { public static class MyEntity {
@Id @Id