HQL maps incorrect field when using inheritance and target entity

Description

Using have a joined hierachy with:

  • Base class BaseEntity

  • Two sub classes ChildEntity1 and ChildEntity2.

  • Both sub classes have a column with the same name (e.g. NAME) which is not in the BaseEntity.

  • Another entity OtherEntity which has a ChildEntity1 property

When doing a JQL join from OtherEntity to ChildEntity1 hibernate appears to disregard which entity the NAME column is on, and picks the one on ChildEntity2 rather than the ChildEntity1 which is specified in the query (see below).

e.g.

Base Class:

Child Entity 1:

Child Entity 2:

Other Entity:

Repository:

Turning on Hibernate query logging logging.level.org.hibernate.SQL=DEBUG shows the query becomes:

This is incorrect. The where clause should be on baseentity1_2_.name

This seems to be a result of using the @ManyToOne(targetEntity = BaseEntity.class) which for this simple example is not required, but for many more advanced hierachies will be.

Environment

None

Activity

Show:
Chris Cranford
May 9, 2018, 1:25 PM

Could it be because both your child entities are using the same discriminator value?

Assignee

Unassigned

Reporter

Ed Wilson

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Feedback Requested

2018/05/10

Feedback Requested By

Chris Cranford

Components

Affects versions

Priority

Major
Configure