Foreign key mapping inside Embeddable class

人盡茶涼 提交于 2019-12-03 11:06:56

Don't put relationships into ID classes, neither for @IdClass or @EmbeddedId ones. An @Embeddable class may only include the annotations @Basic, @Column, @Temporal, @Enumerated, @Lob, or @Embedded. Everything else is provider-specific syntax (e.g. Hibernate allows this, but since you're using EclipseLink, which is the JPA RI, I doubt this is what you want).

Here's an example JPA PK/FK mapping:

@Entity
@Table(name = "Zips")
public class Zip implements Serializable
{
    @EmbeddedId
    private ZipId embeddedId;

    @ManyToOne
    @JoinColumn(name = "country_code", referencedColumnName = "iso_code")
    private Country country = null;

    ...
}

@Embeddable
public class ZipId implements Serializable
{
    @Column(name = "country_code")
    private String countryCode;

    @Column(name = "code")
    private String code;

    ...
}

HTH

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!