cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Razumovsky Andrey <>
Subject Re: State of DataObjects (uncommitted but nonexistent on DB)
Date Sat, 01 Mar 2008 09:13:19 GMT
Hi Adrian,

If i understood your message right, you're manually changing objects' state to COMMITED. Well,
i too think this is not a good idea.
What would i do in this cause is to make those still non-existing in DB objects using default
constructor, so that they would bу TRANSIENT. After that (i think this should be done before
calling 'commitChanges', if you don't want to mess with listeners) you should register user-modified
objects with Cayenne using 'context.registerNewObject()'. The objects should be registered
only if they are TRANSIENT and your-business-logic-modified. Once you do that, their state
will change to NEW and they will normally persist. Those objects which are already in DB will
normally work since they are COMMITED or MODIFIED.
Still, if those objects have relationships you use, this would lead to exceptions during commit,
since there is a problem in setting existent objects in relations for transient objects. About
this i would write to list in my next question. However, sutuation will be even worse if you
have falsely-commited objects, as you suggest.
Hope this helps,

AW> Hello list
AW> I have some kind of exotic question concerning state of DataObjects. In a
AW> scenario I would like to create new DataObjects but keep them in a state
AW> so that they only get committed if the user actively changes some default
AW> value.
AW> Look at it like some lazy persist functionality. Let's say I have a
AW> reporting application (which I have not :) ) where I display a matrix to
AW> the user. X-axis are the days, y-axis are the projects. In every field in
AW> the matrix the user could write the hours he worked on the said project on
AW> the specific day. Which means I need to create DataObjects for all fields
AW> in the matrix so that the databinding works and the user can enter values
AW> into all of the fields. But I only want to persist those records which
AW> actually contain a value.
AW> I thought I could do so creating new DataObjects, setting default values
AW> and then immediately changing the state of the new DataObjects to
AW> committed. While this generally works (DataObject changes to modified
AW> once the user enters a value), the persist process of Cayenne is not
AW> amused since it thinks it should update a record in the database which
AW> does not already exist.
AW> So my question. Would there be another possible solution to my problem?
AW> Cheers,
AW> Adrian

View raw message