HQL left join fetch not working in inheritance scenario: org.hibernate.QueryException: could not resolve property

Description

I have the following entity configuration:

Entity.java

The query

throws this exception:

This used to work. I am not expert on HQL specification, so not sure whether this is a bug or intended feature.

Environment

Hibernate - 5.2.15
JVM - 1.8.0_161-b12
Postgresql 9.6.8
Linux 3.13.0-143-generic

Activity

Show:
Chris Cranford
May 29, 2018, 2:17 PM

, I already tracked that down yesterday and linked them.

Christian Beikov
May 29, 2018, 4:05 PM

I think it's

Christian Beikov
June 13, 2018, 5:54 AM

I just started working on this, but whatever happened before was not deterministic. The model you posted has two different collections that aren't compatible with each other, thus it's not possible to join a collection with that name on BaseEntity.
The collections are different because essentially they use a different collection table for each collection in the subtype.

In Hibernate 5.2.13 and before, Hibernate just joins one of the two tables in a non deterministic manner which might lead to unexpected results.
Adding the following mapping to both OneToMany attributes will resolve the issue by using just a single collection table

Ondra David
June 17, 2018, 1:13 PM
Edited

Thank you for the proposal. For the time being, I solved it by renaming the collection in one subtype.

Sai Surekha
April 17, 2020, 5:15 AM

Hi All,

I am upgrading hibernate from 5.1.17 to 5.4.11. I am also facing same issue and scenario is also same. I can not go for rename because it effects lot of files.

@Entity
public class BaseEntity {
@Id
private long id;
}

Child1:

@Entity
public class EntityA extends BaseEntity {
@OneToMany(mappedBy = "entityA")
private Set<EntityC> attributes;
}

Child2:

@Entity
public class EntityB extends BaseEntity {
@OneToMany(mappedBy = "entityB")
private Set<EntityC> attributes;
}

@Entity
public class EntityC
{
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "entityA_id")
@NaturalId
private EntityA entityA;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "entityB_id")
@NaturalId
@XmlTransient
@JsonProperty
private EntityB entityB;
}

Can some one suggest solution for this?

Assignee

Christian Beikov

Reporter

Ondra David

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.2.13

Components

Affects versions

Priority

Major
Configure