This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 241765 - JPA 2.0 Derived identities
Summary: JPA 2.0 Derived identities
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 248291
  Show dependency tree
 
Reported: 2008-07-22 22:04 EDT by Gordon Yorke CLA
Modified: 2022-06-09 10:23 EDT (History)
5 users (show)

See Also:


Attachments
contains the proposed feature and tests (153.92 KB, patch)
2009-01-23 11:59 EST, Chris Delahunt CLA
no flags Details | Diff
feature plus tests (225.10 KB, patch)
2009-02-02 14:02 EST, Chris Delahunt CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gordon Yorke CLA 2008-07-22 22:04:27 EDT
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.
Comment 2 Chris Delahunt CLA 2009-01-23 11:59:32 EST
Created attachment 123556 [details]
contains the proposed feature and tests
Comment 3 Chris Delahunt CLA 2009-02-02 14:02:45 EST
Created attachment 124452 [details]
feature plus tests
Comment 4 Chris Delahunt CLA 2009-02-04 19:56:31 EST
Feature checked in main
Comment 5 Karen Butzke CLA 2009-02-11 15:21:32 EST
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
Comment 6 Chris Delahunt CLA 2009-03-25 14:40:02 EDT
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

Comment 7 Peter Krogh CLA 2009-08-26 09:44:29 EDT
Mass update to change fixed in target.
Comment 8 Peter Krogh CLA 2009-08-26 09:46:47 EDT
Mass update to change fixed in target.
Comment 9 Peter Krogh CLA 2009-08-26 09:50:34 EDT
Mass update to change fixed in target.
Comment 10 Peter Krogh CLA 2009-08-26 09:52:42 EDT
Mass update to change fixed in target.
Comment 11 Pinaki CLA 2010-01-25 10:40:04 EST
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.
Comment 12 Chris Delahunt CLA 2010-01-25 10:49:55 EST
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
Comment 13 Eclipse Webmaster CLA 2022-06-09 10:23:43 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink