Optimistic Locking Exceptions
If HDR receives an OptimisticLockException from the underlying JPA framework, it wraps the exception in oracle.hsgbu.hdr.base.persist.exception.CorePersistenceException with error code HDR_OBJECT_ALREADY_MODIFIED_ERROR. The client application should attempt to query again if necessary and resubmit updates to HDR.
Example 10-1 Optimistic Locking Exception
The following code sample illustrates an optimistic locking exception:
// create an Act SET_II actId = dataTypeFactory.newSET_II("9.989898.5.6.100", "OBS1001", true); Act act = actFactory.newObservation(ActMood.EVN, null, actId); ControlAct controlAct = actFactory.newControlActEvent( dataTypeFactory.nullCD(NullFlavor.NI), dataTypeFactory.nullSET_II(NullFlavor.NI)); controlAct.addOBActRelationship(ActRelationshipType.SUBJ, act); rimService().submit(controlAct); // retrieve two copies of the Act Act retrievedAct1 = retrieveAct(actId); Act retrievedAct2 = retrieveAct(actId); // update the Act ControlAct controlAct2 = actFactory.newControlActEvent( dataTypeFactory.nullCD(NullFlavor.NI), dataTypeFactory.nullSET_II(NullFlavor.NI)); controlAct2.addOBActRelationship(ActRelationshipType.SUBJ, (Act)retrievedAct1.createNewVersion()); rimService().submit(controlAct2); // try updating the same Act with the other retrieved copy ControlAct controlAct3 = actFactory.newControlActEvent( dataTypeFactory.nullCD(NullFlavor.NI), dataTypeFactory.nullSET_II(NullFlavor.NI)); controlAct3.addOBActRelationship(ActRelationshipType.SUBJ, (Act)retrievedAct2.createNewVersion()); try { rimService.submit(controlAct3); } catch (CTBLockingException e) { // One or more objects in the submission // are locked by another process. // // Requery if necessary, and resubmit // updates to HDR. // // In this case, we know the object is // the Observation which was queried and // versioned, but this can be verified by // inspecting the Exception Act requeriedAct = retrieveAct(actId); ControlAct newControlAct = actFactory.newControlActEvent( dataTypeFactory.nullCD(NullFlavor.NI), dataTypeFactory.nullSET_II(NullFlavor.NI)); newControlAct.addOBActRelationship(ActRelationshipType.SUBJ, (Act)requeriedAct.createNewVersion()); rimService.submit(newControlAct); }