Cannot find entity by ID when ID is a one-to-one association

Description

It is not possible to load an entity by an ID when it is mapped similar to the description of example 4 Case (a) of JPA 2.2 specification:

Loading with the following code:

MedicalHistory history = s.find( MedicalHistory.class, patient );

fails with:

Hibernate incorrectly expects the ID to be of type MedicalHistory. It should expect the ID to be of type Person.

Calling #find by the primary key works fine, although I'm not sure this use case is defined by the spec:
MedicalHistory history = s.find( MedicalHistory.class, patient.getSsn() );

In addition, Querying by ID works:
"SELECT h FROM MedicalHistory h WHERE h.patient = :patient"

Environment

None

Activity

Show:
Gail Badner
January 5, 2021, 8:37 PM

I've pushed a test case to master that reproduces the issue. That test is currently annotated with @FailureExpected.

Gail Badner
January 6, 2021, 3:52 AM

There are a couple more FailureExpected tests pushed in commit:
https://github.com/hibernate/hibernate-orm/commit/b40d1251e385a5fdb018f9583a83c472d6da4e8f]

Assignee

Unassigned

Reporter

Gail Badner

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