Modifying Persistent Instances Outside a Transaction
JDO manages updates to the datastore by tracking changes made to persistent instances during a transaction. To avoid losing updates, you should have an active transaction when changing fields of persistent instances. When the transaction commits, the changes are made in the datastore.
However, you can write applications that manage a cache of
nontransactional persistent instances, where the datastore is updated
outside your application. With these applications, the cache becomes
stale relative to the current state in the datastore. But if your
application is made aware of these changes—for example, by receiving a
stream of change notifications—your application can update the cache to
reflect the current state of the datastore instances. The stream might
consist only of the keys of the instances, in which case the application
can simply invalidate the cached instances by calling evict( )
or refresh(
)
.
But if the stream contains not only the keys but also the changed values for persistent fields, your application can use the stream values to update the cached instances to reflect the current contents of the datastore.
With the NontransactionalWrite
property set to false
,
the only way to update nontransactional instances is to invalidate them
in the cache and then fetch the instances from the datastore when they
are next needed. But with NontransactionalWrite
set to true
, your application can update the persistent instances in the ...
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.