persistence@glassfish.java.net

RE: Fix for issue 702

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Thu, 14 Sep 2006 12:21:12 -0400

Hello Markus,
    The code looks good but it will only apply to the DeferredChangeDetectionPolicy. If any other policies are developed or used (say an active change detection policy that calcs changes as they are made) then this validation would not be applicable as well these changes do not really take updatable = false into account.
    Perhaps a better spot for this validation would be within the write cycle (DirectToFieldMapping.writeFromObjectIntoRow()). Validation here, during the write cycle, would apply to any change detection policies and could take into account updatable = false? (ie. if the attribute was updated but the user has marked the column as not updatable )?
    What do you think?
--Gordon
-----Original Message-----
From: Markus.Fuchs_at_Sun.COM [mailto:Markus.Fuchs_at_Sun.COM]On Behalf Of
Markus Fuchs
Sent: Wednesday, September 13, 2006 9:07 PM
To: Tom Ware
Cc: persistence_at_glassfish.dev.java.net
Subject: Fix for issue 702


Hi Tom,

To address issue "702 - Can't update a primary key of a composite key",
I added validation preventing updates to primary key fields.

I've changed DeferredChangeDetectionPolicy to call
DatabaseMapping.calculateValidatedChange instead of
DatabaseMapping.compareForChange directly.
DatabaseMapping.calculateValidatedChange calls compareForChange to
prepare the ChangeRecord for the field, and than does the validation, if
the ChangeRecord is not null (= the field has been set or updated). Any
updates to primary key fields are disallowed. Setting primary key fields
for inserts is allowed, of course! I added a ValidationException and
changed ValidationExceptionResource for that purpose.

EntityManagerJUnitTestSuite now has two new tests:

a) that the correct exception if thrown in case of a primary key update
b) that updating a primary key field with the same value is allowed

The entity-persistence-tests pass on Oracle. Please do the code-review.

Thank you!

-- markus.