We're updating the issue view to help you get more done. 

Failure getting a PluralAttributePath for collection declared in a superclass marked @Entity

Description

The fix for changed the collection role to be constructed using the entity that is the path source instead of the entity that declares the collection.

For example, here is a simplified version of the test added for HHH-10556, SuperclassCollectionTest:

{{
@MappedSuperclass
public class PersonBase {
@Id @GeneratedValue
Integer id;
@OneToMany(cascade = CascadeType.ALL)
List<Address> addresses = new ArrayList<Address>();
}

@Entity
public class Person extends PersonBase {
...
}
}}

In the following CriteriaQuery:

{{
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object> cq = cb.createQuery();
Root<?> root = cq.from( Person.class );
cq.select( root.get( "addresses" ) )...
}}

the collection role constructed for Person.addresses is "...Person.addresses", even though addresses is declared in PersonBase. I believe this is only correct in this case because PersonBase is a mappedsuperclass. IIRC, the role for a collection in a mappedsuperclass is considered to be in subclasses marked {@Entity} that extend a mappedsuperclass.

If another subclass is added:

{{
@Entity
public class OtherPerson extends Person {
}
}}

and the CriteriaQuery is changed to:

{{
...
Root<?> root = cq.from( OtherPerson.class );
cq.select( root.get( "addresses" ) )...
}}

the collection role constructed for OtherPerson.addresses is "...OtherPerson.addresses", which causes the CriteriaQuery to fail because there is no such collection role. The constructed collection role should be "..Person.addresses" as well.

Environment

None

Status

Assignee

Gail Badner

Reporter

Gail Badner

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

5.0.8
5.1.0

Priority

Major