0

I'm trying to delete a collection of objects, but somehow they still remain.

List<Assignment> assignments = shift.getAssignments();
shift.getObjectContext().deleteObjects(assignments);
shift.getObjectContext().commitChanges();

After commitChanges executed, the only assignment in the collection has this value:

[{<ObjectId:Assignment, assignment_id=26067>; committed; // snipped for clarity

I thought that after deleteObject(), the state would be DELETED; and after commitChanges(), it should not remain in the collection. According to this: http://cayenne.apache.org/docs/3.0/persistent-object-lifecycle.html.

What am I missing?

EDIT: changed the code to remove a different data object which in turn propagate changes to the assignments.

Tuan
  • 1,476
  • 13
  • 23
  • See the answer below on the delete rules. What is suspect in your example though is "committed" state of assignment after delete and commit. It should be "transient". It appears that the objects are not deleted at the point where you print this statement. There's not enough information here to guess why. Do you also see DELETE SQL statements in the logs (specifically for ID 26067) and do those happen before or after you print out the Assigmnent state? – andrus_a Sep 20 '14 at 06:36
  • Yeah, I'm not sure what's going on with that "committed" state. I'm not able to recreate the same problem now. But I think part of the problem is that there was a callback creating assignments without me knowing. I found it after I looked into the log. – Tuan Sep 22 '14 at 19:00

1 Answers1

1

If you want the objects to be removed from collection on delete you can do one of the two things:

  • Manually remove them by iterating over a collection copy and calling "removeFromAssignments()"
  • Define a NULLIFY delete rule for the assignment -> shift relationship
andrus_a
  • 2,528
  • 1
  • 16
  • 10