The deletion of objects has to be part of a transaction as the writing too.
The method sampleDelete() at first reads in a query all Person objects from the database and then deletes them in turn using:
pm.deletePersistent(...);The source code of the sampleDelete() method looks like this:
public void sampleDelete()
{
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
tx.begin();
Query q = pm.newQuery(Person.class);
Collection c = (Collection) q.execute();
Iterator it = c.iterator();
while (it.hasNext()){
pm.deletePersistent(it.next());
}
q.close(c);
tx.commit();
pm.close();
}