HHH-16049 Test setting a property to its current value with bytecode enhancement enabled

This commit is contained in:
Andrea Boriero 2023-01-17 12:50:28 +01:00 committed by Andrea Boriero
parent 5bd1f7c05b
commit 3d9a1bce9b
4 changed files with 26 additions and 14 deletions

View File

@ -82,7 +82,7 @@ public class LazyLoadingByEnhancerSetterTest extends BaseCoreFunctionalTestCase
}
@Test
// @FailureExpected( jiraKey = "HHH-10747" )
@FailureExpected( jiraKey = "HHH-10747" )
public void testProperty() {
doInHibernate( this::sessionFactory, s -> {
ItemProperty input = new ItemProperty();

View File

@ -84,8 +84,9 @@ public class EagerAndLazyBasicUpdateTest extends BaseCoreFunctionalTestCase {
entity.setLazyProperty1( null );
} );
// We should not update entities when property values did not change
statementInspector().assertNoUpdate();
// When a lazy property is modified Hibernate does not perform any select
// but during flush an update is performed
statementInspector().assertUpdate();
}
@Test
@ -128,8 +129,9 @@ public class EagerAndLazyBasicUpdateTest extends BaseCoreFunctionalTestCase {
entity.setLazyProperty1( "lazy1_update" );
} );
// We should not update entities when property values did not change
statementInspector().assertNoUpdate();
// When a lazy property is modified Hibernate does not perform any select
// but during flush an update is performed
statementInspector().assertUpdate();
}
@Test
@ -197,7 +199,7 @@ public class EagerAndLazyBasicUpdateTest extends BaseCoreFunctionalTestCase {
initNonNull();
doInHibernate( this::sessionFactory, s -> {
LazyEntity entity = s.get( LazyEntity.class, entityId );
entity.setEagerProperty( "eager_update" );
entity.setEagerProperty( "eager_initial" );
} );
// We should not update entities when property values did not change
@ -229,8 +231,9 @@ public class EagerAndLazyBasicUpdateTest extends BaseCoreFunctionalTestCase {
entity.setLazyProperty1( null );
} );
// We should not update entities when property values did not change
statementInspector().assertNoUpdate();
// When a lazy property is modified Hibernate does not perform any select
// but during flush an update is performed
statementInspector().assertUpdate();
}
@Test
@ -306,8 +309,9 @@ public class EagerAndLazyBasicUpdateTest extends BaseCoreFunctionalTestCase {
entity.setLazyProperty2( null );
} );
// We should not update entities when property values did not change
statementInspector().assertNoUpdate();
// When a lazy property is modified Hibernate does not perform any select
// but during flush an update is performed
statementInspector().assertUpdate();
}
@Test

View File

@ -83,8 +83,9 @@ public class OnlyLazyBasicUpdateTest extends BaseCoreFunctionalTestCase {
entity.setLazyProperty1( null );
} );
// We should not update entities when property values did not change
statementInspector().assertNoUpdate();
// When a lazy property is modified Hibernate does not perform any select
// but during flush an update is performed
statementInspector().assertUpdate();
}
@Test
@ -153,8 +154,9 @@ public class OnlyLazyBasicUpdateTest extends BaseCoreFunctionalTestCase {
entity.setLazyProperty2( null );
} );
// We should not update entities when property values did not change
statementInspector().assertNoUpdate();
// When a lazy property is modified Hibernate does not perform any select
// but during flush an update is performed
statementInspector().assertUpdate();
}
@Test

View File

@ -119,6 +119,12 @@ public class SQLStatementInspector implements StatementInspector {
.allSatisfy( sql -> Assertions.assertThat( sql.toLowerCase( Locale.ROOT ) ).doesNotStartWith( "update" ) );
}
public void assertUpdate() {
Assertions.assertThat( sqlQueries )
.isNotEmpty()
.anySatisfy( sql -> Assertions.assertThat( sql.toLowerCase( Locale.ROOT ) ).startsWith( "update" ) );
}
public static SQLStatementInspector extractFromSession(SessionImplementor session) {
return (SQLStatementInspector) session.getJdbcSessionContext().getStatementInspector();
}