Programming__WebObjects-EOF-Using EOF-Deleting

Version 3.1 by hschottm on 2008/03/27 03:21

Deleting in EOF

Usually deleting is pretty easy:


Person person; //Assume is an EO that exists
EOEditingContext ec = person.editingContext(); //Always make sure you are using the correct editing context
ec.deleteObject(person); //Mark the EO for deletion
ec.saveChanges(); //Commit

A little more robust example:


Person person; /Assume is an EO that exists
EOEditingContext ec = person.editingContext();
ec.deleteObject(person);

try {
 ec.saveChanges();
} catch (Exception e) {
 //something bad happened, the delete didn't occur
 //well don't just stand there, do something about it!
 ec.revert(); // clean up the mess
}

NOTE: These examples assume that correct EOEditingContext locking is occuring, ProjectWonder's ERXEC auto-locking is highly recommended.