Persistence of Instances

A class is persistent if it has been specified in a JDO metadata file and enhanced. An instance of a persistent class can be either transient or persistent. The JDO specification refers to a persistent class as persistence-capable to emphasize that while a class provides support for persistence, it allows instances to be transient or persistent. We just use the phrase persistent class and note that instances can be either transient or persistent. We refer to classes that are not persistent as transient classes . All instances of a transient class are transient.

All instances of transient and persistent classes that you construct in your applications are initially transient. They become persistent explicitly when you pass them to makePersistent( ), or implicitly if they are referenced by a persistent instance at transaction commit.

Explicit Persistence

You can call the following PersistenceManager method to make a transient instance persistent explicitly:

void makePersistent(Object obj);

You must call it in the context of an active transaction, or a JDOUserException is thrown.

Get Java Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.