Hi Gordon,
The pk update validation is now implemented in
DatabaseMapping.writeFromObjectIntoRowWithChangeRecord(), and is called
from the derived classes AbstractDirectMapping, OneToOneMapping, and
AggregateObjectMapping. The classes ValidationException and
ValidationExceptionResource haven't changed. I also added one more test
for overlapping primary/foreign keys to EntityManagerJUnitTestSuite.
The JUnit tests on Oracle and JavaDB are successful. What do you think?
Thanks!
-- markus.
Gordon Yorke wrote:
>Actually I wasn't precise enough. The actual method would be writeFromObjectIntoRowWithChangeRecord(), If not changeRecord.getOwner().isNew() then you must have an update to this attribute and if this.isPrimaryKeyMapping() then you have an error case. There is no need to have the old value to validate that the error occured the fact that the method is called indicates the mapping was updated.
>--Gordon
>
>-----Original Message-----
>From: Markus.Fuchs_at_Sun.COM [mailto:Markus.Fuchs_at_Sun.COM]On Behalf Of
>Markus Fuchs
>Sent: Friday, September 15, 2006 2:22 PM
>To: persistence_at_glassfish.dev.java.net
>Subject: Re: Fix for issue 702
>
>
>Hi Gordon,
>
>Thinking more about adding the pk update validation in the write phase,
>I see two problems:
>
>* How do I know what kind of operation
>DirectToFieldMapping.writeFromObjectIntoRow() is called for? I.e. insert
>or update (or even delete?)?
>* Do I have access to the previous field value at this point, to compare
>new and old value?
>
>Thank you!
>
>-- markus.
>
>Gordon Yorke wrote:
>
>
>
>>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.
>>
>>
>>
>>
>>
>>
>>
>>