Skip Headers

# Configuring Query Timeout at the Query Level

Previous

Next

You can set the maximum amount of time that TopLink waits for results from a query. This forces a hung or lengthy query to abort after the specified time has elapsed. TopLink throws a `DatabaseException` after the timeout interval.

To specify a timeout interval on a per-query basis, use `DatabaseQuery` method `setQueryTimeout` and pass the timeout interval as an integer representing the number of seconds before the timeout interval should occur, as Example: DatabaseQuery Timeout shows.

DatabaseQuery Timeout

    // Create the appropriate query and set timeout limits
    ReadAllQuery query = new ReadAllQuery(Employee.class);
    query.setQueryTimeout(2);
    try{
        Vector employees = (Vector)session.executeQuery(query);
    }
    catch (DatabaseException ex) {
        // timeout occurs
    }

To specify a timeout interval for all queries on a particular object type, configure a query timeout interval at the descriptor level (see "Configuring Query Timeout at the Descriptor Level").