HHH-11147 - Add back assertions to BatchFetchProxyTest checking that batches are
initialized as expected. Also add a test that ensures that entities loaded from a batch can be modified.
This commit is contained in:
parent
7e71843a50
commit
668253b364
|
@ -61,9 +61,16 @@ public class BatchFetchProxyTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
assertEquals( 1, statistics.getPrepareStatementCount() );
|
assertEquals( 1, statistics.getPrepareStatementCount() );
|
||||||
assertEquals( NUMBER_OF_ENTITIES, employees.size() );
|
assertEquals( NUMBER_OF_ENTITIES, employees.size() );
|
||||||
|
|
||||||
// trigger loading all of the Employee#employer references which should trigger the batch fetching
|
for ( int i = 0; i < employees.size(); i++ ) {
|
||||||
for ( Employee employee : employees ) {
|
final Employer employer = employees.get( i ).employer;
|
||||||
Hibernate.initialize( employee.employer );
|
if ( i % 10 == 0 ) {
|
||||||
|
assertFalse( Hibernate.isInitialized( employer ) );
|
||||||
|
Hibernate.initialize( employer );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assertTrue( Hibernate.isInitialized( employer ) );
|
||||||
|
}
|
||||||
|
assertEquals( "Employer #" + employer.id, employer.name );
|
||||||
}
|
}
|
||||||
|
|
||||||
// assert that all 20 Employee and all 20 Employers have been loaded
|
// assert that all 20 Employee and all 20 Employers have been loaded
|
||||||
|
@ -136,6 +143,48 @@ public class BatchFetchProxyTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-11147")
|
||||||
|
public void testBatchEntityLoadThenModify() {
|
||||||
|
inTransaction(
|
||||||
|
session -> {
|
||||||
|
final Statistics statistics = sessionFactory().getStatistics();
|
||||||
|
statistics.clear();
|
||||||
|
|
||||||
|
List<Employer> employers = new ArrayList<>();
|
||||||
|
for ( int i = 0 ; i < NUMBER_OF_ENTITIES ; i++ ) {
|
||||||
|
employers.add( session.load( Employer.class, i + 1) );
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals( 0, statistics.getPrepareStatementCount() );
|
||||||
|
|
||||||
|
for ( int i = 0 ; i < NUMBER_OF_ENTITIES ; i++ ) {
|
||||||
|
final Employer employer = employers.get( i );
|
||||||
|
if ( i % 10 == 0 ) {
|
||||||
|
assertFalse( Hibernate.isInitialized( employer ) );
|
||||||
|
Hibernate.initialize( employer );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assertTrue( Hibernate.isInitialized( employer ) );
|
||||||
|
}
|
||||||
|
assertEquals( "Employer #" + employer.id, employer.name );
|
||||||
|
employer.name = employer.name + " new";
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals( 2, statistics.getPrepareStatementCount() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
inTransaction(
|
||||||
|
session -> {
|
||||||
|
for ( int i = 0; i < NUMBER_OF_ENTITIES; i++ ) {
|
||||||
|
final Employer employer = session.get( Employer.class, i + 1 );
|
||||||
|
assertEquals( "Employer #" + employer.id + " new", employer.name );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
|
|
Loading…
Reference in New Issue