cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: Replace Objects in a Database?
Date Thu, 29 Nov 2007 20:14:28 GMT
In the nearest future we'll be adding a "merge" method to the  
DataContext that would do exactly what you described here - reattach  
an already persistent and possibly modified object to the context. For  
now the closest analog is "localObject", but it will require some  
hacking. A reattach method may look like this:

void reattach(Persistent object) {
     // force "modified" on the object
     context.localObject(object.getObjectId(), object);

This will do the right thing for objects not changed, but WILL NOT do  
the right thing for the newly inserted objects.


On Nov 29, 2007, at 1:33 PM, Detlef Burt wrote:

> Hello,
> after being able to keep my Data after sending my Objects via JMS  
> (Thanks Andrus) I now have a problem when I try to write the Objects  
> back into the Database.
> After sending the Objects to the Client-Application, the Client  
> changes some data ( Just a timestamp in my Testcase ) and then sends  
> an Update-Request to the Server. Due to the fact, that the Client  
> has no access to the DataContext or the underlying ObjectStore, the  
> changes made to the Object won't be recorded.
> After the Server receives the Object, it reconnects the Object to  
> the DataContext, thus being able to get a snapshot from the database  
> or even create an UpdateQuery.
> But I can't go anywhere from here.
> Executing the UpdateQuery won't have any effect because Cayenne  
> doesn't know what changed.
> I also tried to get a Snapshot from the DB, convert my DataObject to  
> a DataRow and then create and register the diff of those by myself.  
> But I couldn't find anything like that :/
> To sum it all up:
> - Can I tell Cayenne to replace the Database Contents with the data  
> from my Object while retaining the ObjectId ?
> - Can I tell Cayenne to "scan" an Object for changes and register  
> the differences, so that calling commitChanges will update the Object?
> - Or is it possible to create a DataRow from a DataObject so I can  
> create and register an ObjectDiff ?
> When updating the Object, I don't know what class is being updated  
> and what properties it has, all I have is my  
> CayennePersistableObject Baseclass, which extends CayenneDataObject.
> Detlef

View raw message