After discussing this issue with Christian Beikov, we came to the conclusion the the original mapping, though it worked in Hibernate 5, is not valid. This JPA spec paragraph about Primary Keys Corresponding to Derived Identities says:
The identity of an entity may be derived from the identity of another entity (the “parent” entity) when the former entity (the “dependent” entity) is the owner of a many-to-one or one-to-one relationship to the parent entity and a foreign key maps the relationship from dependent to parent.
This is not the case for the SpecialProduct primary key, where the wholesalePrice property is an unowned @OneToOne association (having mappedBy), thus having no actual columns on the SPECIAL_PRODUCTS table. The correct behavior should be an explicit error signaling the mapping problem to the user. The correct mapping should just exclude the wholesalePrice property from the SpecialProductPK used as IdClass. |