cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fredrik Liden" <>
Subject RE: creating/saving transient objects to database
Date Thu, 21 Jun 2007 22:10:19 GMT
If you're calling newObject you'll get a registered object with
PersistenceState.NEW. so consequently the commit tries to insert it.

I'm thinking at some point you'll need to manually check if the object
exists in the database or not based on some criteria. Maybe you can
create a service class that checks using a query if the Pojo object
exists in the db. If it does it returns the existing DataObject and if
not it returns the object using newObject. Then the persistenceState
will be either NEW or COMMITED and commit will trigger insert and update

Of course the Cayenne guys probably have some other nifty way to do it.


-----Original Message-----
From: Michael Lepine [] 
Sent: Thursday, June 21, 2007 2:46 PM
Subject: creating/saving transient objects to database

I've got a situation where I've got strict POJO objects that I'll need
copy data from and into my generated Cayenne classes. My issue is that
I copy the data from the bean to the Cayenne class, I don't know whether
object exists or not. Thus, I create the Cayenne class instance using
DataContext.newObject(). Obviously, when I call
an insert is being attempted on the corresponding table even if a record
already exists in the database.

Is there a way to create the Cayenne instance so that the persistent
will know to check whether the record exists and update it instead of
attempting an insert?

Any help and guidance are appreciated.

View raw message