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:
answer.setPersistenceState(PersistenceState.DELETED);
to:
dataContext.deleteObject(answer);
/dev/mrg
On 4/7/07, Michael Lepine <mikelepin..mail.com> 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();
>
This archive was generated by hypermail 2.0.0 : Sat Apr 07 2007 - 14:11:54 EDT