Community
Participate
Working Groups
JPA 2.0 will provide functionality allowing developers to use relationship mappings as primary keys or primary key components. For example, a developer marks a relationship mapping like a OneToOne with @Id and the FK is used in the Primary key. EclipseLink has this functionality but the Annotation processing / PK class validation layer must be updated with this support.
See http://wiki.eclipse.org/EclipseLink/Development/JPA2.0/derived_ids
Created attachment 123556 [details] contains the proposed feature and tests
Created attachment 124452 [details] feature plus tests
Feature checked in main
The feature doc says this feature was not supposed to include mapped-by-id support. I do not see another enhancement entered for this work, am I missing it? Also, the eclipselink_orm_1_1.xsd needs to be updated to include the id and mapped-by-id attributes on the appropriate mappings. Or the eclipseLink-orm_1_1.xsd needs to be copied and named eclipselink-orm_2_0.xsd, or just renamed, whichever is the plan. Maybe this is part of another bug as well
Mappedbyid support will be added through feature https://bugs.eclipse.org/bugs/show_bug.cgi?id=270011 and is described at: http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/mappedbyid
Mass update to change fixed in target.
A typical Order-LineItem definition where LineItem uses compound, derived identity. Is this mapping supported in 1.1.0.r3634 or any later available versions? The mapping fails with following error message (detailed stack trace at the end) [java] Caused by: Exception [EclipseLink-7149] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.ValidationException [java] Exception Description: The composite primary key attribute [order] of type [class domain.PurchaseOrder] on entity class [class domain.LineItem] should be of the same type as defined on its primary key class [domain.LineItemId]. That is, it should be of type [long]. Here are the entity definitions: A "parent" entity with a simple identity of a long field ------------------------------------------------------------- @Entity public class PurchaseOrder implements Serializable { @Id private long id; } ------------------------------------------------------------- A "child" entity that -- uses a separate Id class -- uses a compound identity -- derives part of its identity from "parent" ------------------------------------------------------------- @Entity @IdClass(LineItemId.class) public class LineItem implements Serializable { @Id @ManyToOne private PurchaseOrder order; // field name must match the field name in LineItem.LineItemId @Id @OrderColumn @Column(name="IDX") // index is keyword private int index; // field name must match the field name in LineItem.LineItemId --------------------------------------------------------------- And the separate Id class --------------------------------------------------------------- public class LineItemId implements Serializable { long order; int index; The runtime fails with the following error: [java] Caused by: Exception [EclipseLink-7149] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.ValidationException [java] Exception Description: The composite primary key attribute [order] of type [class domain.PurchaseOrder] on entity class [class domain.LineItem] should be of the same type as defined on its primary key class [domain.LineItemId]. That is, it should be of type [long]. [java] at org.eclipse.persistence.exceptions.ValidationException.invalidCompositePKAttribute(ValidationException.java:1082) [java] at org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor.validatePKClassId(MetadataDescriptor.java:1438) [java] at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor.process(IdAccessor.java:65) [java] at org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor.processAccessors(MetadataDescriptor.java:1082) [java] at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.processAccessorsClassAccessor.java:636) [java] at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processAccessors(EntityAccessor.java:611) [java] at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.process(EntityAccessor.java:530) [java] at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:446) [java] at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:303) [java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:838) While the error message is fairly clear (thanks:) why it thinks the mapping definitions are wrong, here is the JPA 2.0 spec (sec 2.4.1.1: Specification of Derived Identities) "If the dependent entity uses an id class to represent its primary key, one of the two following rules must be observed:" // lines ommitted "If an Id attribute in the entity is a many-to-one or one-to-one relationship to a parent entity, the corresponding attribute in the id class must be of the same Java type as the id class or embedded id of the parent entity (if the parent entity has a composite primary key) or the type of the Id attribute of the parent entity (if the parent entity has a simple primary key)." My reading is LineItem (child) having a @Id @ManyToOne PurchaseOrder and LineItem using @IdClass(LineItemId.class) fit into the above spec scenario.
Eclipse Persistence Services - 1.1.0.r3634 has support for JPA 1.0. The target for this bug was Eclipselink 1.2, but full JPA 2.0 support was targeted for EclipseLink 2.0. Please try 2.0.0 or later for JPA 2.0 support
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink