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 - 13:59:39 EDT