Use of subcriterias produce inconsistent results

Description

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.

Environment

Hibernate, MySql

Status

Assignee

Gail Badner

Reporter

Felipe Carasso

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.7
3.6.10

Priority

Major
Configure