Skip Headers

# Disabling the Identity Map Cache Update During a Read Query

Previous

Next

To disable the identity map cache update, which is normally performed by a read query, call the `dontMaintainCache` method. This improves the query performance when you read objects that are not needed later by the application and can avoid exceptions during partial object queries (see "Reading Objects Using Partial Object Queries").

Disabling the Identity Map Cache Update

Example: Disabling the Identity Map Cache Update demonstrates how code reads `Employee` objects from the database and writes the information to a file.

    // Reads objects from the employee table and writes them to an employee file
    void writeEmployeeTableToFile(String filename, Session session) {
        Vector employeeObjects;
        // Create ReadAllQuery and set Employee as its reference class
        ReadAllQuery query = new ReadAllQuery(Employee.class);
        ExpressionBuilder builder = query.getExpressionBuilder();
        query.setSelectionCriteria(builder.get("id").greaterThan(100));
        query.dontMaintainCache();
        Vector employees = (Vector) session.executeQuery(query);
        // Write all the employee data to a file
        Employee.writeToFile(filename, employees);
    }