Skip Headers

# Reading Objects Using Report Queries

Previous

Next

Example: Querying Reporting Information on Employees reports the total and average salaries for Canadian employees grouped by their city.

Querying Reporting Information on Employees

    ExpressionBuilder emp = new ExpressionBuilder();
    ReportQuery query = new ReportQuery(Employee.class, emp);
    query.addMaximum("max-salary", emp.get("salary"));
    query.addAverage("average-salary", emp.get("salary"));
    query.addAttribute("city", emp.get("address").get("city"));

    query.setSelectionCriteria(emp.get("address").get("country").equal("Canada"));
    query.addOrdering(emp.get("address").get("city"));
    query.addGrouping(emp.get("address").get("city"));
    Vector reports = (Vector) session.executeQuery(query);

The `Report` `Q` `uery` class provides an extensive reporting API, including methods for computing average, maximum, minimum, sum, standard deviation, variance, and count of attributes. For more information about the available methods for the `Report` `Q` `uery`, see the Oracle TopLink API Reference.

Note: Because `ReportQuery` inherits from `ReadAllQuery`, it also supports most `ReadAllQuery` properties.