Exception when using CriteriaBuilder to access generic embedded ID in MappedSuperclass

Description

CriteriaBuilder throws an exception when trying to build a select based on an embeddedId property if the entity extends MappedSuperclass and the MappedSuperclass contains a generic embedded ID.

Issue occurs with the following mappedSuperclass for composite keys (EmbeddedId) and concrete entities implementing this abstract superclass:

Now the issue is that if multiple entities exist and I try to access an ID property of an entity with CriteriaBuilder, an exception is thrown (for all except one entity):

Seems that the metamodel maps all of my entities to the same MappedSuperclass instance. During application startup, the properties of the `@EmbeddedId` returned by `newId()` are set to the id type attributes of the MappedSupperclass, *overwriting* the id type attributes of the previous entity. So in the end, all entities are mapped to the same MappedSupperclass, but the MappedSupperclass only has the id type attributes of the last entity.

I have create a test case here.

Probably related to and (however these issues only mention issues with getting the correct type, while in my case the query creation fails).

Environment

None

Activity

Show:
Maciej Karaś
August 5, 2019, 7:58 AM
Edited

We also stumbled upon this bug in every tested version of Hibernate 5+, even the newest for date, 5.4.4.

In Hibernate 4.3.7 it works without problem, so I see it as a regression.

Assignee

Unassigned

Reporter

Dominic Lerbs

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure