Skip Headers

# orderSibling Parameter

Previous

Next

The `orderSibling` parameter in the expression specifies the order in which the query returns sibling objects in the hierarchy. This parameter mirrors the Oracle Database `ORDER SIBLINGS` clause.

To include an `orderSibling` parameter, define a vector, and to include the order criteria, use the `addElement` method. Pass the vector as the third parameter in the `setHierarchicalQueryClause` method. If you do not specify an order, set this value to `null`.

Hierarchical Query

    ReadAllQuery raq = new ReadAllQuery(Employee.class);
    // Specifies a START WITH expression
    Expression startExpr = expressionBuilder.get("id").equal(new Integer(1));
    // Specifies a CONNECT BY expression
    Expression connectBy = expressionBuilder.get("managedEmployees");
    // Specifies an ORDER SIBLINGS BY vector
    Vector order = new Vector();
    order.addElement(expressionBuilder.get("lastName"));
    order.addElement(expressionBuilder.get("firstName"));
    raq.setHierarchicalQueryClause(startExpr, connectBy, order);
    Vector employees = uow.executeQuery(raq);

This code generates the following SQL:

    SELECT * FROM EMPLOYEE START WITH ID=1 CONNECT BY PRIOR ID=MANAGER_ID ORDER SIBLINGS BY LAST_NAME, FIRST_NAME