Community
Participate
Working Groups
Build Identifier: I-3.4.0-20111227220343 An validation error is given against the subclass Dependent with the case below saying "An ancestor of this class has already defined the primary key. Primary key attributes may not be defined here." but the subclass is just using a MapsId, not really defining a primary key. Based on our understanding of MapsId -- it marks an existing primary key field as being reused for a relationship, the validation error is invalid. @MappedSuperclass public abstract class Person { @Id int empId; } public class Dependent extends Person { @ManyToOne @MapsId protected Employee emp; } **Please comment if you have different understanding of MapsId. Reproducible: Always
Dependent class given in the bug description should be annotated with @Entity.
I assume this only applies to Generic platforms? Did we get input from the EclipseLink guys on this?
yes, the problem only appears with Generic platforms.
Paul...can you comment on this?
I suppose it's a matter of interpretation. From the spec: "If the dependent entity has a single primary key attribute (i.e, the relationship attribute or an attribute that corresponds to the relationship attribute) and the primary key of the parent entity is a simple pri-mary key, the primary key of the dependent entity is a simple primary key of the same type as that of the parent entity (and neither EmbeddedId nor IdClass is specified). In this case, either (1) the rela-tionship attribute is annotated Id, or (2) a separate Id attribute is specified an d the relationship attribute is annotated MapsId (and the value element of the MapsId annotation is not specified)." Does the relationship determine the id? Or does the id determine the relationship? Also from the spec: "If a many-to-one or one-to-one entity relationship corresponds to a primary key attribute, the entity con-taining this relationship cannot be persisted without the relationship having been assigned an entity since the identity of the entity containing the relationship is derived from the referenced entity." It seems to me in this case that the relationship is determining the id, and therefore, whether the dependent class chooses to model this as a @ManyToOne @Id or a @ManyToOne @MapsId with a separate @Id field is just matter of choice, but that the mechanism is the same - the relationship is determined first, then the id.