Restoring Values at Transaction Rollback
We have seen how an application can retain persistent field values
in cached instances across transactions by using the RetainValues
property. But this property is
effective only at commit. If you want to preserve cached values even if
a transaction rolls back, you need to use the RestoreValues
property. Unlike RetainValues
, RestoreValues
is not an optional feature, and
the property setting affects the treatment of new instances as well as
persistent-clean and persistent-dirty instances.
With RestoreValues
set to
false
, persistent transactional
instances have their values cleared at transaction rollback, and the
instances transition to hollow. This is shown in Figure 14-3. Subsequent reads of
fields in these instances require access to the datastore. In order to
allow accesses of the values in the instances without accessing the
datastore, the application sets the RestoreValues
flag to true
.
Figure 14-3. Rollback with RestoreValues true
Similar to RetainValues
, there
are several ways to set the RestoreValues
property:
Your application can include the
javax.jdo.option.RestoreValues
property with a value oftrue
orfalse
in theProperties
instance used to construct thePersistenceManagerFactory
.Your application can set the property using
setRestoreValues( )
inPersistenceManagerFactory
.Your application can set the property using
setRestoreValues( ...
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.