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.

Rollback with RestoreValues 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 of true or false in the Properties instance used to construct the PersistenceManagerFactory.

  • Your application can set the property using setRestoreValues( ) in PersistenceManagerFactory.

  • Your application can set the property using setRestoreValues( ...

Get Java Data Objects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.