JPA (Hibernate, EclipseLink) mapping: why doesn't this code work (chain of 2 relationships using JPA 2.0, @EmbeddedId composite PK-FK)?

血红的双手。 提交于 2019-12-01 18:15:21

Simply removing the @Embedded annotation from within the EmbeddedId types that reference the dependant EmbeddedIds may resolve your issue.:

    @Embeddable
    public class FooId implements Serializable
    {
        // no annotation.
        private PostAddressId postAddressId; //just one field!

        ...
    }

    ...
        @MapsId(value = "postAddressId")
        @OneToOne
        @JoinColumns(value = {@JoinColumn(name = "contact_id", referencedColumnName = "contact_id"), @JoinColumn(name = "ordinal_nbr", referencedColumnName = "ordinal_nbr")})
        private PostAddress postAddress = null;
 

(EDIT): Another issue is the use of the FooId. This class should not be used. The ID class for Foo Enitity is the PostAddressId and the OneToOne "postAddress" should simply be marked @Id and not @MapsId. Likewise BarId should not have an Embedded defined but should directly reference the PostAddressId. The Bar Mapping that references PostAddress should use MapsId.

Please file a bug against EclipseLink for the terrible exception and if removing the @Embedded and the other updates in the edit does not resolve your issue please file an EclipseLink bug for that as well.

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