Skip Headers

# Noncascading Write Queries

Previous

Next

When you execute a write query, it writes both the object and its privately owned parts to the database by default. To build write queries that do not update privately owned parts, include the `dontCascadeParts` method in your query definition.

Use this method to do the following:

- Increase performance when you know that only the object's direct attributes have changed.

- Resolve referential integrity dependencies when you write large groups of new, independent objects.

  Note: Because the unit of work resolves referential integrity internally, this method is not required if you use the unit of work to write to the database.

Performing a Noncascading Write Query

    // the Employee is an existing employee read from the database
    Employee.setFirstName("Bob");
    UpdateObjectQuery query = new UpdateObjectQuery();
    query.setObject(Employee);
    query.dontCascadeParts();
    session.executeQuery(query);