8.14. Closing

public boolean isClosed ();
public void close ();

When a PersistenceManager is no longer needed, call its close method. In an unmanaged environment, closing a PersistenceManager releases any resources it is using. The persistent objects managed by the PersistenceManager become invalid, as do any Query, Extent, and Sequence instances it created. Calling any method other than isClosed on a closed PersistenceManager results in a JDOUserException. You cannot close a PersistenceManager that is in the middle of a transaction in an unmanaged environment.

In a managed environment where transactions are controlled by an external TransactionManager, closing a PersistenceManager returns it to a pool, where it remains associated with the current global transaction. The PersistenceManager does not free its resources until the global transaction ends. In this environment, it is good practice to obtain the PersistenceManager from the PersistenceManagerFactory at the beginning of each business method, and to close it at the end of each method. The JDO implementation will ensure that you always receive the same PersistenceManager within the same transactional context.


Skip navigation bar   Back to Top