persistence@glassfish.java.net

RE: Code review for issue 1356

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Thu, 26 Oct 2006 09:53:18 -0400

looks good Markus,
    Please check it in.
--Gordon

-----Original Message-----
From: Markus.Fuchs_at_Sun.COM [mailto:Markus.Fuchs_at_Sun.COM]On Behalf Of
Markus Fuchs
Sent: Wednesday, October 25, 2006 8:17 PM
To: Gordon Yorke; persistence_at_glassfish.dev.java.net
Subject: Code review for issue 1356


Hi Gordon,

please review the fix for issue 1356 - NPE near mergeChangesIntoObject

The reason for the NPE is that the wrong descriptor is used to create
the ObjectChangeSet for a related entity. The descriptor used is that
for the declared relationship field type, but the value is an instance
of a sub-class. The descriptor of the super class doesn't know about
the additional fields in the sub-class, and can't find the mapping to be
used to merge the changes for these fields, causing the NPE. This can
be fixed by changing method
ObjectReferenceMapping.getDescriptorForTarget from

   public ClassDescriptor getDescriptorForTarget(Object object,
AbstractSession
session) {
       return getReferenceDescriptor();
   }

to

   public ClassDescriptor getDescriptorForTarget(Object object,
AbstractSession
session) {
       return session.getDescriptor(object);
   }

I added a new test, EntityManagerJUnitTestCase, using the inheritance
model to test this situation. The test fails w/o my fix. All
entity-persistence-tests succeed with my change.

Thanks for the review!

-- markus.