JPA EclipseLink ManyToMany with Data

℡╲_俬逩灬. 提交于 2019-12-12 05:12:56

问题


I'm currently trying to implement a ManyToMany Relationship with Data in the JoinTable. I'm following this approach with the Eclipselink JPA Framework. But I'm getting the following exception:

org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:210) ... 23 more Caused by: Exception [EclipseLink-7298] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.ValidationException Exception Description: The mapping [group] from the embedded ID class [class de.kapieren.mbm.server.model.UserGroupPK] is an invalid mapping for this class. An embeddable class that is used with an embedded ID specification (attribute [pk] from the source [class de.kapieren.mbm.server.model.GroupMembership]) can only contain basic mappings. Either remove the non basic mapping or change the embedded ID specification on the source to be embedded

Does anybody know whats the meaning of basic mappings in relationship to embeddedId? What could be wrong here?


回答1:


EclipseLink is complaining about the use of non Basic mappings (for example a ManyToOne) in an Embeddable class used as a primary key (i.e. annotated with EmbeddedId).

And according to the JPA 2.0 specification, this is indeed not supported:

11.1.15 EmbeddedId Annotation

The EmbeddedId annotation is applied to a persistent field or property of an entity class or mapped superclass to denote a composite primary key that is an embeddable class. The embeddable class must be annotated as Embeddable. Relationship mappings defined within an embedded id class are not supported.

If I rephrase, the EmbeddedId's Embeddable class must define each id attribute for the entity using Basic mappings in standard JPA.

References

  • JPA 2.0 Specification
    • Section 11.1.15 "EmbeddedId Annotation"


来源:https://stackoverflow.com/questions/4013397/jpa-eclipselink-manytomany-with-data

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