Have bag fetches revert to subselect fetching if there are other collection fetches

Description

When using EAGER fetching in @OneToMany realtionship and @ElementCollection in a related entity, the returned data is multiplied.

Consider following case with a tree like structure:
We have entities A (root), B (nodes) and C (additional data of B).
A has relationship @OneToOne to B.
B has relationship @OneToMany to B and @OneToOne to C.
C has @ElementCollection (a map).

In the B parent entity is a list of B children. If the relationship is eager then elements on the list are multiplied as many times as there are elements in C's @ElementCollection.

Workaround:
If you annotate @OneToMany eager relationship with @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT) the problem will not occur.

I will provide Hibernate ORM 5 Test Case shortly.

Environment

It looks like the problem affects all environments.

Activity

Show:
Michał Piotrowski
October 10, 2017, 10:33 AM
Gail Badner
October 10, 2017, 8:02 PM

Without @OrderColumn, Hibernate models your @OneToMany association as a "bag". If you add @OrderColumn, your test passes.

will fix this issue.

Assignee

Unassigned

Reporter

Michał Piotrowski

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure