cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Lewis <>
Subject Re: how to catch updates just before commit
Date Fri, 28 Apr 2006 19:49:00 GMT
Hmm, I must be missing something.  I looked at CAY-414 and looked for
related changes in the latest code, but didn't grok it.  I tried the
validateFor methods, but they still get called for phantom changes... I
tried adding to a to-many and setting an attribute to its current
value.  Tried the latest nightly jar.

This isn't an urgent thing for me.  I'll wait a while and check again. 

Andrus Adamchik wrote:

> I suggest overriding the validateFor* methods. This was problematic 
> in the past, but now Cayenne guarantees that validation methods are 
> called only for the objects that will be committed (i.e. those with 
> "phantom" modifications are not validated).
> Andrus
> On Apr 28, 2006, at 12:40 PM, Bryan Lewis wrote:
>> We have a time-when-last-modified timestamp column in most of our 
>> tables
>> to serve as an optimistic-locking attribute.  At present we're setting
>> it with a bit of inelegant code that imitates the way we used to do it
>> in our old WebObjects days... we have a saveChanges() method that  wraps
>> dc.commitChanges().  Before the commit we can timesstamp the  newObjects
>> and modifiedObjects.
>> The trouble is, this sets the timestamp on objects that haven't really
>> been modified... an attribute was set to the same value it already  had,
>> or a to-many relationship was added to.  Cayenne figures out later in
>> the pipeline that those other changes aren't real and doesn't generate
>> SQL for them.  How can I hook into that later point, and set the
>> timestamp only if the row is about to be updated?  I looked at
>> DataContextDelegate, but I guess that's for external changes.  The 
>> event
>> mechanism looks closer, although the docs say that dc.onSync() isn't
>> intended for direct use.  Worst case, I could compare the object's
>> current values to the snapshot but that seems reinventing the  plumbing.
>> Thanks.

View raw message