cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simran Narula <>
Subject RE: Track Column level changes in Cayenne
Date Thu, 05 Apr 2012 03:54:15 GMT
Hey Andrus,

Thanks for your reply that day. 

Just wanted to let you know this Worked !!

Thanks heaps for help !

-----Original Message-----
From: Andrus Adamchik [] 
Sent: Wednesday, 28 March 2012 6:50 PM
Subject: Re: Track Column level changes in Cayenne

(reposting from stackoverflow answer)

There are a few ways to approach this. Here is the one that IMO is the most transparent. The
trick is to use a different ObjectContext from the one committing changes. Then you will get
a separate copy of the object that will contain currently saved value:

    // 'this' refers to the DataObject being committed (assuming things happen in its callback)
    ObjectContext parallelContext = ... // create a new context here like you normally would

    // 3.1 API; 3.0.x has a similar method with a slightly different sig
    MyClass clone = parallelContext.localObject(this);

    // if you are ok with cached old value, ignore the 'invalidateObjects' call.
    // If not, uncomment it to ensure the object gets refetched. 
    // Also 3.1 API. Should be easy to adjust for 3.0
    // parallelContext.invalidateObjects(clone);

    Object oldValue = clone.getXyz();


On Mar 28, 2012, at 7:58 AM, Simran Narula wrote:

> Hi,
> I need to log each action taken on my portal UI for e.g.
> Price changed for product x
> Assume all the information is contained within one table i.e.both price & the product
> When the portal is loaded with product information, user can change the price of the
> I want to check if the price has changed or not and for that I am using a pre-update
call back in Cayenne entity to check these changes, I want to check if the price x is changed
to Y and push another history record in the Database. So far I have tried cache strategies
- NO_CACHE and other workarounds but no success yet.
> surely I can achieve this by other hacky means, but do not want to. My question is...
is there any way to track column level changes in Cayenne ?
> Thanks.
> Simran

View raw message