On 22/06/2007, at 7:41 PM, Thomas Gilbert wrote:
Using Cayenne (2.0) I'm trying to put in place the following
mechanism:
<...>
I would like to automatically change de last_modif_date and
modified_by columns whenever an update is done on a records (e.g.
when setBlabla() is called).
I already tried to use DataContextDelegate like this
public boolean shouldMergeChanges(DataObject object, DataRow
snapshotInStore)
{
if (object instanceof ScmsCase)
{
((ScmsCase)object).setLastModificationDate(new Date());
((ScmsCase)object).setModifiedBy(m_szUserID);
}
return true;
}
The hook is called when needed but the changes does not seem to be
committed. Also note that finishedMergeChanges is not triggered.
Is it the right way to achieve this ? Are they other ways ?
Though modifications are discouraged in validateForSave that's
another option short of utilising the Lifecycle callbacks in 3.0.
Note that the lifecycle callbacks have to be enabled manually at this
time... though hopefully in the (near) future they'll become part of
the normal operations of Data/ObjectContexts.
See bottom of: http://cayenne.apache.org/doc/lifecycle-callbacks.html
with regards,
--
Lachlan Deck