Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
At commit time, a unit of work and its contents expire: you must not use the unit of work nor its clones even if the transaction failed and rolled back.
However, TopLink offers an API that lets you continue working with a unit of work and its clones:
commitAndResume
: Commits the unit of work, but does not invalidate it or its clones.
commitAndResumeOnFailure
: Commits the unit of work. If the commit transaction succeeds, the unit of work expires. However, if the commit transaction fails, this method does not invalidate the unit of work or its clones. This method lets you modify the registered objects in a failed unit of work and retry the commit transaction.
You should resume a unit of work only in an application that makes repeated changes to the same, small dataset. Reusing the same unit of work while accessing different datasets may result in poor performance.
Example 102-9 shows how to use the commitAndResume
method.
Example 102-9 Using the commitAndResume Method
UnitOfWork uow = session.acquireUnitOfWork(); PetOwner petOwnerClone = (PetOwner)uow.readObject(PetOwner.class); petOwnerClone.setName("Mrs. Newowner"); uow.commitAndResume(); petOwnerClone.setPhoneNumber("KL5-7721"); uow.commit();
The commitAndResume
call produces this SQL:
UPDATE PETOWNER SET NAME = 'Mrs. Newowner' WHERE (ID = 400)
Then, the commit
call produces this SQL:
UPDATE PETOWNER SET PHN_NBR = 'KL5-7721' WHERE (ID = 400)