Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-dev] Bug 241765 - JPA 2.0 Derived identities

Hello Pinaki,
   The version of EclipseLink you are using is very old and is not JPA 2.0
compatible.  You will need to upgrade to EclipseLink 2.0
--Gordon


Pinaki Poddar wrote:
> 
> Hi,
>   While the error message is fairly clear 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. 
> 
>   Regards --
> 
> Pinaki
>  
> 
> Pinaki Poddar wrote:
>> 
>> Hi,
>>   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)
>> 
>> 
>>   
>>    
>> 
>> 
>> 
>> christopher delahunt wrote:
>>> 
>>> Bug 241765 - JPA 2.0 Derived identities
>>> Checked into main.
>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=241765
>>> reviewed by Gordon and Guy
>>> _______________________________________________
>>> eclipselink-dev mailing list
>>> eclipselink-dev@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-dev
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Bug-241765---JPA-2.0-Derived-identities-tp21810451p27408118.html
Sent from the EclipseLink - Dev mailing list archive at Nabble.com.



Back to the top