cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Lewis <jbryanle...@gmail.com>
Subject Re: Any way to check if object has really changed?
Date Tue, 24 Mar 2009 15:16:33 GMT
Yep, we've been using essentially the same code to detect real changes to
objects so that we can keep an audit trail of all changes.  However, we did
run into one little special case.

If the object has a to-one relationship that's toDependentPK, and it happens
to have a null current value, it will always appear to have changed.  The
old value always appears to be non-null because the dbAttribute is the
source object's primary key.  We had to modify the last 'if' statement from:

    if (!Util.nullSafeEquals(dbval, objval))

to:

    if (!Util.nullSafeEquals(dbval, objval)
       && !(DataObjectUtils.pkForObject(p) == null &&
dbr.isToDependentPK()))

This causes us to miss removals (nullifying) of such a relationship but
that's a rare occurrence.  Would be glad to hear a better way.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message