Reputation: 1486
I have the following code:
List<Assignment> assignments = objectContext.performQuery(assignmentQuery);
objectContext.commitChanges();
objectContext.deleteObjects(assignments);
objectContext.commitChanges();
I do the first commitChanges()
to commit all the queries. Then I clear Cayenne's log. On the second commitChanges()
, this shows up on the log:
INFO : QueryLogger.logBeginTransaction: 2013-07-10 07:37:11,214: --- transaction started.
INFO : QueryLogger.logQuery: 2013-07-10 07:37:11,218: INSERT INTO scheduler_assignment
...
INFO : QueryLogger.logQuery: 2013-07-10 07:37:11,241: DELETE FROM scheduler_assignment
...
INFO : QueryLogger.logCommitTransaction: 2013-07-10 07:37:11,286: +++ transaction committed.
I don't understand why it is doing the INSERT statement when I'm trying to delete. Can anyone explain? Thanks!
Upvotes: 0
Views: 357
Reputation: 2563
The only logical explanation is that your ObjectContext is "dirty" - it contains other uncommitted objects in addition to what is shown here. This can happen for a variety of reasons, 2 most common being:
(1) ObjectContext scope is too wide and changes to the context are originating from some other place in the app.
(2) changes originating from callbacks/listeners during commit.
Some hints on scoping of ObjectContexts:
Upvotes: 1