cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Gentry" <>
Subject Re: Delete query not generating as expected
Date Sat, 07 Apr 2007 18:11:26 GMT
It looks like you are setting the persistence state manually to
DELETED.  You shouldn't really need to ever modify the persistence
state yourself (Cayenne manages it), although sometimes it is useful
to get the state.  Instead, you need to tell the DataContext to delete
the object -- just like you tell the DataContext to create new objects
and to perform queries.

Try changing:





On 4/7/07, Michael Lepine <> wrote:
> I'm experiencing something confusing when committing changes with a
> DataContext and objects to be deleted. I have a list of CayenneDataObjects
> that I'm either updating or deleting depending on parameters set in a web
> client. I've included the code below.
> When I debug the code, I can see the PersistanceState of the objects.
> Initially, the PersistanceState is COMMITTED. After the for loop, the
> objects that did have a delete flag set, do have a PersistanceState of
> DELETED (as expected). So, when the DataContext.commitChanges() method
> executes, it only generates and runs the update query. It does not generate
> the delete query as I'd expect it to. After the commitChanges() executes,
> the objects that had a PersistanceState of DELETED now have a
> PersistanceState of TRANSIENT, and obviously, the records still exist in the
> database.
> Does anyone have any ideas that I could try? This is driving me crazy. I'm
> sure I'm missing something very simple.
> Thanks for any help you can offer.
> // MerchElementSupportedAnswer is a subclass of CayenneDataObject
> *for* (MerchElementSupportedAnswer answer : answers) {
>     // if data for answer was deleted, delete record
> *    if* (answer.isDeleteFlag()) {
>         answer.setPersistenceState(PersistenceState.*DELETED*);
> *        continue*;
>     }
>     answer.setToMerchElementDefinitions(getElementDefinition(dataContext));
>     answer.setLastUpdatedDate(lastUpdatedDate);
> }
> dataContext.commitChanges();

View raw message