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.

Activity

Show:

Sai Surekha April 17, 2020 at 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?

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

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

Christian Beikov June 13, 2018 at 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

Christian Beikov May 29, 2018 at 4:05 PM

I think it's

Chris Cranford May 29, 2018 at 2:17 PM

, I already tracked that down yesterday and linked them.

Incomplete

Details

Assignee

Reporter

Worked in

Components

Priority

Created May 28, 2018 at 2:35 PM
Updated April 17, 2020 at 5:15 AM
Resolved June 19, 2018 at 7:50 AM