Skip Headers

# Write Query Overview

Previous

Next

To execute a write query, use a `WriteObjectQuery` instance instead of using the `writeObject` method of the session. Likewise, substitute `DeleteObjectQuery`, `UpdateObjectQuery`, and `InsertObjectQuery` objects for their respective `Session` methods.

Using a WriteObjectQuery

    WriteObjectQuery writeQuery = new WriteObjectQuery();
    writeQuery.setObject(domainObject);
    session.executeQuery(writeQuery);

Using InsertObjectQuery, UpdateObjectQuery, and DeleteObjectQuery

    InsertObjectQuery insertQuery= new InsertObjectQuery();
    insertQuery.setObject(domainObject);
    session.executeQuery(insertQuery);

    /* When you use UpdateObjectQuery without a unit of work, UpdateObjectQuery writes all direct attributes to the database */
    UpdateObjectQuery updateQuery= new UpdateObjectQuery();
    updateQuery.setObject(domainObject2);
    session.executeQuery(updateQuery);

    DeleteObjectQuery deleteQuery = new DeleteObjectQuery();
    deleteQuery.setObject(domainObject2);
    session.executeQuery(deleteQuery);