124 Transaction management 7.3.3.2 Reacting to optimistic concurrency
Advanced transaction options 125 Now we see the problem. A JDOUserException is thrown by the JDO implementation when the commit of the optimistic transaction was attempted. I presume that the application will redisplay the data and invite User1 to make his changes again (manual resolution). When the fields of the Hollow instance are read and displayed, the values will be retrieved from the data store, and the description Red Tables will be shown. However, the Persistent-Nontransactional instance will likely yield an outdated description of Green Tables. Thus, in response to an optimistic transaction failure, the user is being presented with transactionally inconsistent data. (This specific problem arises when an instance is read in an optimistic transaction and is not altered within that transaction, but is altered by another transaction.) Some implementations may choose to invalidate all instances involved in a failed optimistic transaction, essentially making them Hollow. This is not strictly correct, but as has been illustrated above would be extremely helpful. 7.3.4 Resolution using explicit refresh The solution to the quandary described above is to explicitly refresh each instance involved in an optimistic transaction failure before the data is redisplayed to the user. Unfortunately there is no means to achieve this automatically through the JDO API, which requires the application to maintain a list of instances involved in an optimistic transaction expressly for this purpose. Since the code which handles commit failures may not be part of the code that manipulates instances within the transaction, this problem may be non-trivial. Most of the JDO vendors agree that optimistic transactions are under-specified in JDO, and will be adding additional API calls to handle cases such as this. No doubt a future version of JDO will combine their best efforts under a revision of the standard API. 7.4 Advanced transaction options We now look at ways in which applications can access persistent data outside the context of an active transaction. Recall that persistence and transactionality can be applied to instances in any combination. We say that the two concepts are orthogonal; just because the instance is persistent does not mean that it is necessarily transactional. 7.4.1 NontransactionalRead and Write If the NontransactionalRead flag on a Transaction is true, then the field values of Hollow and Non-transactional instances can be read without an active transaction.
Hint: This post is supported by Gama web hosting hrvatska services