0 Replies Latest reply on Dec 2, 2016 3:44 PM by brouveure

    Toplink support for database mapping of varray of object types

    brouveure

      As per documentation given by Oracle middleware for Toplink supports:

       

      1. 1) Nested table mapping
      2. TopLink ObjectRelationalDescriptor for each structured type (Struct/object-type).
      3. TopLink supports only arrays (Varrays) of basic types or arrays on structured types (Struct/object-type)

      Please find the below link for your reference.

      http://docs.oracle.com/cd/E14571_01/web.1111/b32441/introorp.htm#JITDG92174

       

      However, we are getting an error while trying to implement this feature in a Java project.  Please find below the details.   Can you please review and let us know the cause of the error? Can you also let us know if such an implementation is support and provide an working example for the same?

       

      CREATE OR REPLACE type RecordIncarnationType as object (RecordId Varchar2(40 CHAR), KnowledgeDateStart Timestamp, KnowledgeDateEnd Timestamp);

       

      --RecordIncarnationTableArr

       

      CREATE OR REPLACE Type RecordIncarnationTableArr As Varray(40) Of RecordIncarnationType;

       

      Create Table Instrument

      (

        AssetSubType             Varchar2(30 Char),

        TriangularCurrency     Varchar2(3 Char),

        RecordIncarnation      RecordIncarnationTableArr,

         )

       

      Entity

      1. InstrumentEntity.java

      @Entity

      @Table(name = "INSTRUMENT")

      @Customizer(value = InstrumentCustomizer.class)

      public class InstrumentEntity implements Serializable {

      @Column(name = "RECORDINCARNATION", columnDefinition = "RECORDINCARNATIONTABLEARR")

             private List<RecordIncarnation> recordIncarnation;

        }

       

      public class RecordIncarnation implements Serializable{

             /**

              *

              */

             private static final long serialVersionUID = 1L;

             private String recordId;

       

             private Timestamp knowledgeDateStart;

       

             private Timestamp knowledgeDateEnd;

       

             public RecordIncarnation() {

             }

            

             public String getRecordId() {

                    return recordId;

             }

       

             public void setRecordId(String recordId) {

                    this.recordId = recordId;

             }

       

             public Timestamp getKnowledgeDateStart() {

                    return knowledgeDateStart;

             }

       

             public void setKnowledgeDateStart(Timestamp knowledgeDateStart) {

                    this.knowledgeDateStart = knowledgeDateStart;

             }

       

             public Timestamp getKnowledgeDateEnd() {

                    return knowledgeDateEnd;

             }

       

             public void setKnowledgeDateEnd(Timestamp knowledgeDateEnd) {

                    this.knowledgeDateEnd = knowledgeDateEnd;

             }

            

       

      public class InstrumentCustomizer implements DescriptorCustomizer {

       

             public void customize(ClassDescriptor descriptor) {

                   

                    ReferenceMapping managerMapping = new ReferenceMapping();

                  managerMapping.setReferenceClass(RecordIncarnation.class);

                  managerMapping.setAttributeName("recordIncarnation");

                  descriptor.addMapping (managerMapping);

                 

                  ObjectArrayMapping recordIdMapping = new ObjectArrayMapping();

                  recordIdMapping.setReferenceClass(RecordIncarnation.class);

                  recordIdMapping.setAttributeName("recordId");

                  recordIdMapping.setFieldName("RECORDID");

                  recordIdMapping.setStructureName("RECORDID");

                  descriptor.addMapping (recordIdMapping);

                 

                  ObjectArrayMapping kdsMapping = new ObjectArrayMapping();

                  kdsMapping.setReferenceClass(RecordIncarnation.class);

                  kdsMapping.setAttributeName("knowledgeDateStart");

                  kdsMapping.setFieldName("KNOWLEDGEDATESTART");

                  kdsMapping.setStructureName("KNOWLEDGEDATESTART");

                  descriptor.addMapping (kdsMapping);

                 

                  ObjectArrayMapping kdeMapping = new ObjectArrayMapping();

                  kdeMapping.setReferenceClass(RecordIncarnation.class);

                  kdeMapping.setAttributeName("knowledgeDateEnd");

                  kdeMapping.setFieldName("KNOWLEDGEDATEEND");

                  kdeMapping.setStructureName("KNOWLEDGEDATEEND");

                  descriptor.addMapping (kdeMapping);

             }

      }

            

       

      }

       

       

      Exception [EclipseLink-110] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException

      Exception Description: Descriptor is missing for class [com.multifonds.ae2.coherence.entity.RecordIncarnation].

      Mapping: org.eclipse.persistence.mappings.structures.ObjectArrayMapping[knowledgeDateEnd]

      Descriptor: RelationalDescriptor(com.multifonds.ae2.coherence.entity.InstrumentEntity --> [DatabaseTable(INSTRUMENT)])

       

      Runtime Exceptions:

      ---------------------------------------------------------

       

      1. java.lang.ClassCastException: org.eclipse.persistence.internal.helper.DatabaseField cannot be cast to org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField