Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-2667

Fix Issues with Generic Vertical Inheritance

    XMLWordPrintableJSON

Details

    Description

      I discovered a couple issues when trying to implement Vertical Inheritance using Generic Persistent Classes (Java-less)

      The 1st issue is that one of the Subclasses will get the wrong Qualifier assigned because the wrong ObjEntity is returned during BaseContext.injectInitialValue because the MappingCache.objEntitiesByClassName is keyed by class-name so it can only hold one of the possible many generic ObjEntities.

      See Test and DataMap implementing a Generic Student that has sub Entities of a Generic Boy and a Generic Girl.

      It inserts 2 records into [gen_student], 1 record into [gen_boy], 1 record into [gen_girl], but the [type] on both student records is "G", instead of one "B" and one "G".

      When creating the GenBoy ... the line:
      getEntityResolver().getObjEntity(object.getClass()) its returning the "Girl" ObjEntity
      the MappingCache.objEntitiesByClassName holds an entry for "CayenneDataObject" with value for Girl ObjEntity. When using Generics there will be many ObjEntities that use CayenneDataObject, so we shouldn't be asking for it from this cache Map.

      instead we should use: getEntityResolver().getObjEntity((Persistent)object) because that one is properly getting the correct ObjEntity from the ObjectId, in MappingCache.getObjEntity(Persistent object)

      The 2nd issue is that when querying for GenStudents, it returns the correct records, but only the Girl is populated and the Boy is HOLLOW, because the query generated does not do a left join to gen_boy.

      ObjectSelect.query(DataObject.class, "GenStudent").select(context);
      

      This happens because PersistentDescriptor.subclassDescriptors is a map keyed by a class name, so the 2nd one overwrites the first one. This map should be keyed by the ObjEntity name to support Generic Persistent Classes.

      There is a test included that will show that with my fixes the PersistentDescriptor.subclassDescriptors now can hold the 2 ClassDescriptors for the 2 generic Sub ObjEntities.

      Attachments

        Activity

          People

            ntimofeev Nikita Timofeev
            mattraydub Matt Watson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h