When managing the persistence of objects using a PersistenceManager it is normal to handle all datastore operations in a transaction. For this reason each PersistenceManager has its own transaction. Consequently a typical JDO persistence method will look something like this
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin(); // Start the PM transaction
... perform some persistence operations
tx.commit(); // Commit the PM transaction
}
finally
{
if (tx.isActive())
{
tx.rollback(); // Error occurred so rollback the PM transaction
}
}JDO supports the two main forms of transaction
pm.currentTransaction().setOptimistic(true);