Nested ID class using derived identifiers fails with strange AnnotationException: unable to find column reference in the @MapsId mapping: `game_id`
Description
Attachments
Activity

Christian BeikovNovember 6, 2020 at 4:03 PM
Thanks for verifying and the test case, I’ll take a deeper look when I find some time.

Ka WuNovember 6, 2020 at 11:20 AM
Yes:
Fails as well…

Christian BeikovNovember 6, 2020 at 9:59 AM
Could you try one more thing, rename the getter and setter to getScore
and setScore
as that is the name that is required by the spec AFAIU.

Ka WuNovember 6, 2020 at 9:37 AM
Thanks for checking.
I tried without these artificial PK class xetters:
Same result when running the gradle tests:
Fail.

Christian BeikovNovember 5, 2020 at 9:10 AM
According to the JPA specification section 2.4.1.1 something similar should indeed be possible. I’m citing the section here:
The names of the attributes of the id class and the Id attributes of the dependent entity class
must correspond as follows:
• The Id attribute in the entity class and the corresponding attribute in the id class must
have the same name.
• If an Id attribute in the entity class is of basic type, the corresponding attribute in the
id class must have the same type.
• If an Id attribute in the entity is a many-to-one or one-to-one relationship to a parent
entity, the corresponding attribute in the id class must be of the same Java type as the
id class or embedded id of the parent entity (if the parent entity has a composite primary
key) or the type of the Id attribute of the parent entity (if the parent entity has a
simple primary key).
Maybe the JPA TCK does not assert this, which would be unfortunate. I see this being specifically mentioned in the section 2.4.1.3 so you are right, it should work. What bugs me is that you have additional getters and setters. Have you tried removing the getGameId
and getHome
methods from the id class already? I’m not sure if that is allowed. At least I don’t see it being specified in the JPA spec.
Details
Assignee
Christian BeikovChristian BeikovReporter
Ka WuKa WuLabels
Components
Fix versions
Priority
Critical
Details
Details
Assignee

Reporter

Consider the following classes:
This results in: