| I am not really sure if it is a bug or a user error on my end. But I'm fairly certain that I do everything correctly. Premisses / things known to work:
- Composite @NaturalId see
HHH-11255 Closed
- @ManyToOne mapping with composite Primary Keys
- @ManyToOne mapping with @NaturalId
Expectation: @ManyToOne mapping with non-primary embedded key (e.g. @NaturalId) Example:
class Region {
@NaturalId
@Embedded
private PostalCode postalCode;
}
@Embeddable
@MappedSuperclass
class PostalCode {
protected String countryCode;
protected int zipCode;
}
class Town {
@NaturalId
@Embedded
private TownCode townCode;
@ManyToOne
@JoinColumns(value = {
@JoinColumn(name = "country_code", referencedColumnName = "country_code"),
@JoinColumn(name = "zip_code", referencedColumnName = "zip_code")
}
private Region region;
}
class TownCode extends PostalCode {
protected String town;
}
Result:
The error message sounds like I did a mistake. But I specified the mapped property via the @JoinColumns-Annotation. This mapping would work if it were a primary key. Additionally it would probably be helpful if one could add the property/ies to map as a @ManyToOne parameter. But that probably will require an JPA API change if I understand this correctly. |