Let’s consider that we have two entities: Course and Student, where Student has many Course(s), a one-to-many relation like in the below example:
Please note that the courses field in Student is eagerly fetched. Starting from these entities we’ve generated some entries in the database:
Later, we want to retrieve these entities and we have two options: Option #1 - Everything works as expected we have students with courses.
Option #2 - Doesn’t work as expected starting with version 5.3.11.Final. We have students… but no courses linked to them.
When we need to use the second option, due to performance reasons, we are not able to obtain entities with their EAGER fields fetched and we think this behaviour should be corrected. Note: (We hope we will not influence your judgment related to this task…) Debugging inside hibernate code, we’ve found that once with the changes related to https://hibernate.atlassian.net/browse/HHH-11147 the following line was added in org.hibernate.internal.ScrollableResultsImpl#prepareCurrentRow :
which further resulted in having a StatefulPersistenceContext#loadCounter equal with 1, and when StatefulPersistenceContext#initializeNonLazyCollections is invoked nothing is executed due to the first check if ( loadCounter == 0 ) {... Attached a set of two tests (in AppTest) highlighting the problem. |