Skip to content

Commit

Permalink
HHH-16049 Test setting a property to its current value with bytecode …
Browse files Browse the repository at this point in the history
…enhancement enabled
  • Loading branch information
dreab8 committed Jan 24, 2023
1 parent ac55bb2 commit 802fc76
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testField() {
}

@Test
// @FailureExpected( jiraKey = "HHH-10747" )
@FailureExpected( jiraKey = "HHH-10747" )
public void testProperty() {
doInHibernate( this::sessionFactory, s -> {
ItemProperty input = new ItemProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,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
Expand Down Expand Up @@ -130,8 +131,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
Expand Down Expand Up @@ -199,7 +201,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
Expand Down Expand Up @@ -231,8 +233,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
Expand Down Expand Up @@ -308,8 +311,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,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
Expand Down Expand Up @@ -154,8 +155,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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();
}
Expand Down

0 comments on commit 802fc76

Please sign in to comment.