Making a Persistent Instance Transient
Suppose you have a persistent instance that you want to make
accessible to a client application via Remote Method Invocation (RMI). Suppose your code is
executing in a Common Object Request Broker Architecture (CORBA) or
application-server environment, where the transaction context will no
longer exist once your servlet or session bean returns from a client
invocation. When RMI serializes your instance, the transaction is no
longer active. You do not want the PersistenceManager
to mediate access to a
persistent instance outside of a transaction context. So, to pass the
persistent instance to a remote client, you must convert it into a
transient instance. This is necessary to disassociate the instance with
the PersistenceManager
, so field
access is not mediated.
You do this by making the persistent instance transient. You can
use the following PersistenceManager
methods to make persistent instances transient:
void makeTransient(Object obj); void makeTransientAll(Object[] objs); void makeTransientAll(Collection objs);
When the instances transition to transient, they lose their
identity and association with the PersistenceManager
. They are no longer
associated with their representation in the datastore, so their
in-memory state does not affect the persistent state in the datastore.
Even though the instance in memory is transient, the instance still
exists in the datastore. Making a persistent instance transient is not
equivalent to calling deletePersistent( ...
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.