|
When using the Criteria API to find entities based on their relationship to a third level entity, Hibernate will hydrate the LAZY collection with incomplete data, except if there are conditions on the second level entity.
In the attached test, the following entities are defined:
A -
(many to many)
> B --(many to many)
-> C
The test then defines a Criteria to list all As related to one specific C using JoinType.LEFT_OUTER_JOIN.
If there's no condition on B, the list of Bs within the As will be initialized with incomplete data, resembling to a wrong EAGER initialization.
When a dummy condition is added on B (list of Cs not empty), then the list of Bs within the As will behave as expected and will be fully initialized only when accessed.
If JoinType.INNER_JOIN is used, the problem does not seem to happen.
|