Skip Headers

# Using Unit of Work Method writeChanges Instead of Conforming

Previous

Next

Using `UnitOfWork` method `writeChanges`, you can write uncommitted changes to the data source: you can execute report queries, noncaching queries, and data read and modify queries against these changes (see Example: Using Unit of Work Method writeChanges).

Using Unit of Work Method writeChanges

    UnitOfWork uow = session.acquireUnitOfWork();
        Pet pet = new Pet();
        Pet petClone = (Pet)uow.registerObject(pet);
        petClone.setId(100);
        petClone.setName("Fluffy");
        petClone.setType("Cat");

    uow.writeChanges();

    // Use uow to perform report, noncaching, and data read and modify queries
    // against the changes made so far

    uow.commit();

However, you can call `writeChanges` only once; any attempt to register objects or to execute object-level queries will throw an exception.

For more information, see "Writing Changes Before Commit Time"