Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Exceptions when using generics (was Upgrade from 1.1.0-M5 to 2.0.2) - bug# 312132 - use targetEntity attribute

Hi Michael!

Wow - thank you very much for your support :-)
I have just checked mails scince my last post, and have found your answers and your efforts to help me - this is really great!

I hope, that I can check your suggestions tomorrow - and I'll let you know, if this solves my problem.

Best regards,
Frank


Am 08.05.10 16:12, schrieb Michael O'Brien:
Frank,
    This issue is one of not enough information on the unidirectional mapping when using parameterized generics - similar to what needs to be done when using Maps.
    There is a workaround that i just verified:

        Set the "targetEntity" on the @ManyToOne or @OneToOne unidirectional mapping
        Use the following mapping annotation where we let Metadata processing know what the target entity is.

     @ManyToOne(targetEntity=MyField.class)
     private F myfield;

    For an example see use cases 1 to 8 for design issue 63 (Map Support) for JPA 2.0
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute


>Still, the validation exception needs to be modified to report the actual problem not the secondary exception
- we don't have enough info in the mapping - not that the @Id processing is failing on default String handling

    With this annotation addition, you will no longer get a ValidationException as seen in the log excerpt below.

LOGS:
[EL Config]: 2010-05-08 10:02:55.922--ServerSession(37462178)--Thread(Thread[Main Thread,5,main])--The alias name for the entity class [class org.eclipse.persistence.example.dataparallel.model.MyField] is being defaulted to: MyField.
[EL Config]: 2010-05-08 10:02:55.962--ServerSession(37462178)--Thread(Thread[Main Thread,5,main])--The alias name for the entity class [class org.eclipse.persistence.example.dataparallel.model.MyClass] is being defaulted to: MyClass.
[EL Config]: 2010-05-08 10:02:56.022--ServerSession(37462178)--Thread(Thread[Main Thread,5,main])--The foreign key column name for the mapping element [field myfield] is being defaulted to: MYFIELD_PU_ID.
[EL Finest]: 2010-05-08 10:02:56.022--ServerSession(37462178)--Thread(Thread[Main Thread,5,main])--End predeploying Persistence Unit dao.create.tables.derby; session file:/C:/wse/wls10330/org.eclipse.persistence.example.dataparallel.client/bin/_dao.create.tables.derby; state Predeployed; factoryCount 0

    thank you
    /michael
Michael O'Brien wrote:
Frank,
   I raised bug# 312132, it will get prioritized before next thursdays' EclipseLink meeting.
JPA: Validation error on parameterized generic OneToOne Entity relationship from MappedSuperclass
http://bugs.eclipse.org/312132

   Feel free to add yourself to the bug, vote on it and/or add your test model as an attachment.

>I took the liberty of completing your unidirectional model by creating an Entity MyField class and either an Entity or MappedSuperclass MyGenericType
I get the same exception as yourself, except for the fact that the validation error occurs on the defining superclass instead of the MyClass subclass in your case.
The fact that F extends a entity MyField should allow this to pass.
I suspect that this issue requires a but at least for defining invalid configurations.

@Entity
public class MyClass extends MyGeneric<MyGenericType>{
   @Id
   private Long id;
}
@MappedSuperclass
public abstract class MyGeneric <F extends MyField > implements MyInterface {
    @ManyToOne
  private F myfield;
}
public interface MyInterface {}

@MappedSuperclass
public abstract class MyGenericType extends MyField {}

@Entity
public class MyField {
   @Id
   private Long id;
}
Exception Description: [class org.eclipse.persistence.example.dataparallel.model.MyGeneric] uses a non-entity [class java.lang.String] as target entity in the relationship attribute [field myfield].
   at org.eclipse.persistence.exceptions.ValidationException.nonEntityTargetInRelationship(ValidationException.java:1327)

>note: MyClass must have an @Id at its level or higher in its mappedSuperclass heirarchy or we get the following
Exception Description: Entity class [class org.eclipse.persistence.example.dataparallel.model.MyClass] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
   at org.eclipse.persistence.exceptions.ValidationException.noPrimaryKeyAnnotationsFound(ValidationException.java:1350)

>The error is actually happening before the 1:1 processing - when we compute the pk field name in getReferenceDescriptor()
       String defaultPKFieldName = getReferenceDescriptor().getPrimaryKeyFieldName();


>The reference descriptor on the MyClass entity is String - which looks wrong to me.
this    OneToOneAccessor  (id=31)      m_referenceClass    MetadataClass  (id=87)          m_type    "java.lang.String" (id=109)  
>Hopefully this is not a case of an unitialized field during mappedSuperclass processing of the pseudo RelationalDescriptor we added for the JPA 2.0 metamodel
- if so it will become design issue 103 after http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_102:_20100421:_Fully_initialize_MappedSuperclass_Descriptors_and_Refactor_existing_workarounds

thank you
/michael




Michael O'Brien wrote:
Frank,
   Correction, I see Entity MyClass extends MappedSuperclass MyGeneric where F is of type MyGenericType
   In this case MyField still must be an Entity, however a MyGenericType subclass of MyField could still be a MappedSuperclass as in an MS-->E hierarchy like CoordinateMS --> GalacticPosition in our JPA test model
UML:
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#Mapped_Superclass_Test_Model
Code:
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/CoordinateMS.java?r=HEAD

   - retesting
   /michael

Michael O'Brien wrote:
Frank,
   Hi, I could find no relationship to the MyClass entity in the MyGeneric mappedSuperclass.
   If MyClass would actually be MyField - then the code should validate ok.
   Could you supply the code for the MyField class (F in this case should be a concrete entity subclass in your client code).
   Normally relationships out of MappedSuperclasses must be only to entities.

   For example I get the following expected exception when i target a MappedSuperclass as the target of a OneToOne

Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class org.eclipse.persistence.example.dataparallel.model.ScalarProcessingUnit] uses a non-entity [class org.eclipse.persistence.example.dataparallel.model.ProcessingUnit] as target entity in the relationship attribute [field westUnit].
   at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:210)

@MappedSuperclass
public abstract class Core {}

@MappedSuperclass
public abstract class ProcessingUnit<P extends Core> implements Serializable {
   @OneToOne
   private ProcessingUnit<P> westUnit;
}

@Entity(name="DparPU")
public class ScalarProcessingUnit extends ProcessingUnit implements Serializable {}

   If I instead reference the entity subclass for the @OneToOne (virtually the same as a  @ManyToOne) -  I no longer get a validation exception.

   @OneToOne
   private ScalarProcessingUnit westUnit;

   thank you
   /michael


Frank von Daak wrote:
Hello again,

after searching the whole day for a solution, I try to get a little help on the list.

After upgrading from Eclipselink 1.1.0 to 2.0.2, I always get Exceptions, when starting up the application:

Caused by: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class de.myapp.domain.MyClass] uses a non-entity [class java.lang.String] as target entity in the relationship attribute [field myfield].

I am using Generics - mabye, this causes the problem!?

The classes look like this:
--------------------------------------------
@Entity
public class MyClass extends MyGeneric<MyGenericType>{
......
}  --------------------------------------------

@MappedSuperclass
@Cache(type=CacheType.NONE, alwaysRefresh=true)
public abstract class MyGeneric <F extends MyField > implements MyInterface {
     @ManyToOne
   private F myfield;  ....
}
--------------------------------------------

What is wrong with this code?
Who can give me a little help?

Thank you very much!
Frank

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top