mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
HHH-16049 Test setting a property to its current value with bytecode enhancement enabled
This commit is contained in:
parent
5bd1f7c05b
commit
3d9a1bce9b
@ -82,7 +82,7 @@ public void testField() {
|
||||
}
|
||||
|
||||
@Test
|
||||
// @FailureExpected( jiraKey = "HHH-10747" )
|
||||
@FailureExpected( jiraKey = "HHH-10747" )
|
||||
public void testProperty() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
ItemProperty input = new ItemProperty();
|
||||
|
@ -84,8 +84,9 @@ public void updateOneLazyProperty_nullToNull() {
|
||||
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 void updateOneLazyProperty_nonNullToNonNull_sameValues() {
|
||||
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 void updateOneEagerProperty_nonNullToNonNull_sameValues() {
|
||||
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 void updateOneEagerPropertyAndOneLazyProperty_nullToNull() {
|
||||
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 void updateAllLazyProperties_nullToNull() {
|
||||
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
|
||||
|
@ -83,8 +83,9 @@ public void updateSomeLazyProperty_nullToNull() {
|
||||
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 void updateAllLazyProperties_nullToNull() {
|
||||
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
|
||||
|
@ -119,6 +119,12 @@ public void assertNoUpdate() {
|
||||
.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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user