DekGenius.com
[ Team LiB ] Previous Section Next Section

12.4 Changes

You can now create new persistent objects and read them from the underlying data store. The next task is to modify your persistent objects. JDO does not require any special work for changes to an object—the changes are automatically reflected in the data store. Deletion, however, requires some work.

Just as the PersistenceManager enables you to create persistent objects through makePersistent( ), it enables you to delete them through deletePersistent( ):

mgr.deletePersietent(book);

The book is now gone from the data store!

From a technical perspective, deletion is this simple. In reality, JDO does you no favors when it comes to managing object relationships. The preceding call would, in fact, delete the book from the data store. But it would also leave its Author object with a NULL value in its list of books. You are responsible for maintaining the integrity of the object relationships:

Collections books = author.getBooks( );
Book book;
   
// loop through the list, find the one you do not want
books.remove(book);
author.setBooks(books);
mgr.deletePersistent(book);

The integrity of your object relationships and the underlying data store integrity are now protected.

    [ Team LiB ] Previous Section Next Section