Skip Headers
Oracle TopLink Developer's Guide
10g Release 3 (10.1.3)
B13593-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Resuming a Unit of Work After Commit

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:

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)