persistence@glassfish.java.net

Code review for issue 1356

From: Markus Fuchs <Markus.Fuchs_at_Sun.COM>
Date: Wed, 25 Oct 2006 17:16:32 -0700

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.