Skip to content

Commit 25929f7

Browse files
committed
work on tests for batch fetching
1 parent 3d49fce commit 25929f7

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/proxy/BatchFetchProxyTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,40 @@ public void testBatchEntityLoadThenModify(SessionFactoryScope scope) {
197197
);
198198
}
199199

200+
@Test
201+
@JiraKey("HHH-11147")
202+
public void testBatchEntityRemoval(SessionFactoryScope scope) {
203+
scope.inTransaction(
204+
session -> {
205+
final Statistics statistics = scope.getSessionFactory().getStatistics();
206+
statistics.clear();
207+
208+
List<Employer> employers = new ArrayList<>();
209+
for ( int i = 0 ; i < 5 ; i++ ) {
210+
employers.add( session.getReference( Employer.class, i + 1) );
211+
}
212+
213+
assertEquals( 0, statistics.getPrepareStatementCount() );
214+
215+
session.find( Employer.class, 0 );
216+
session.find( Employer.class, 1 );
217+
session.find( Employer.class, 2 );
218+
session.find( Employer.class, 5 );
219+
220+
assertEquals( 1, statistics.getPrepareStatementCount() );
221+
222+
session.find( Employer.class, 6 );
223+
session.find( Employer.class, 7 );
224+
225+
assertEquals( 3, statistics.getPrepareStatementCount() );
226+
227+
for ( Employer employer : employers ) {
228+
assertTrue( Hibernate.isInitialized( employer ) );
229+
}
230+
}
231+
);
232+
}
233+
200234
@BeforeEach
201235
public void setUpData(SessionFactoryScope scope) {
202236
scope.inTransaction(

hibernate-core/src/test/java/org/hibernate/orm/test/fetching/BatchFetchingTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import jakarta.persistence.ManyToOne;
1313
import jakarta.persistence.OneToMany;
1414

15+
import org.hibernate.annotations.BatchSize;
1516
import org.hibernate.annotations.NaturalId;
1617
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
1718

@@ -80,7 +81,7 @@ public static class Department {
8081
private Long id;
8182

8283
@OneToMany(mappedBy = "department")
83-
//@BatchSize(size = 5)
84+
@BatchSize(size = 5)
8485
private List<Employee> employees = new ArrayList<>();
8586

8687
//Getters and setters omitted for brevity

0 commit comments

Comments
 (0)