[ https://issues.apache.org/jira/browse/CAY-2667?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17465015#comment-17465015 ]
Nikita Timofeev commented on CAY-2667: -------------------------------------- Hi [~mattraydub], thanks for the reminder! I looked your PR some time ago, unfortunately not as much as I wanted. I found two things that stop me from applying it to the 4.2 branch. # there's incompatible method changes, this is rather technical and I could fix it on my own # I can feel that there could be some performance issues, but I don't have time to test everything thoroughly, and that's a bigger problem for now. Once we branch out 4.2 (and I think we could do it already) I wanted to apply your PR to the next version (4.3?) so it could be tested safely. > Fix Issues with Generic Vertical Inheritance > -------------------------------------------- > > Key: CAY-2667 > URL: https://issues.apache.org/jira/browse/CAY-2667 > Project: Cayenne > Issue Type: Bug > Components: Core Library > Reporter: Matt Watson > Priority: Major > Labels: Generic, inheritance, vertical > Fix For: 4.2.B2 > > Time Spent: 0.5h > Remaining Estimate: 0h > > 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. > {code:java} > ObjectSelect.query(DataObject.class, "GenStudent").select(context); > {code} > 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. -- This message was sent by Atlassian Jira (v8.20.1#820001)