Tuan
Tuan

Reputation: 1486

Deleted collection still exist

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.

Upvotes: 0

Views: 105

Answers (1)

andrus_a
andrus_a

Reputation: 2563

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

Upvotes: 1

Related Questions