Joins over type variable defined relations is non-deterministic

Description

The scenario involves quite some classes. The basic structure is something like

The problem with that model is that e.g. a query like from PolymorphicPropertyBase p left join p.base b left join b.relation1 might sometimes work whereas from PolymorphicPropertyBase p left join p.base b left join b.relation2 will not and vice versa.

The reason for this, is that during the metamodel building hibernate currently resolves p.base to the first type it encounters i.e. either PolymorphicSub1 or PolymorphicSub2. This will make it work for one type, but fail for the other.

The fix I applied is very involved in the metadata building. It detects conflicts(properties of both types) at the junction points(PolymorphicPropertyBase) and changes the properties types to the common super type. This has the effect that p.base will now resolve to PolymorphicBase which will rightfully involve a polymorphic join for all subtypes.

Environment

None

Activity

Show:
Vlad Mihalcea
February 26, 2018, 12:40 PM

Applied PR upstream after some minor modifications.

Assignee

Christian Beikov

Reporter

Christian Beikov

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure