Skip Headers

# Refreshing the Identity Map Cache During a Read Query

Previous

Next

Include the `refreshIdentityMapResult` method in a query to force refreshing of an identity map with the results of the query.

Refreshing the Result of a Query in the Identity Map Cache During a Read Query

    // Create ReadObjectQuery and set Employee as its reference class
    ReadObjectQuery query = new ReadObjectQuery(Employee.class);
    ExpressionBuilder builder = query.getExpressionBuilder();
    query.setSelectionCriteria(builder.get("lastName").equal("Smith"));
    query.refreshIdentityMapResult();
    Employee employee = (Employee) session.executeQuery(query);

The `refreshIdentityMapResult` method refreshes the object's attributes, but not the attributes of its privately owned parts. However, under most circumstances, you should refresh an object's privately owned parts and other related objects to ensure consistency with the database.

To refresh privately owned or related parts, use the following methods:

- `cascadePrivateParts`: Refreshes all privately owned objects

- `cascadeAllParts`: Refreshes all related objects

Using the cascadePrivateParts Method

    ReadAllQuery query = new ReadAllQuery(Employee.class);
    query.refreshIdentityMapResult();
    query.cascadePrivateParts();
    Vector employees = (Vector) session.executeQuery(query);

Note: If the object is in the session cache, you can also use the `refreshObject` method to refresh an object and its privately owned parts.