A colleague asked about how one can implement hierarchical questions using TopLink. There is a section in the manual describing this nicely.
http://www.oracle.com/technology/products/ias/toplink/doc/1013/MAIN/_html/qryadv008.htm#i1134801
The following code snippet is an excerpt from it:
ReadAllQuery raq = new ReadAllQuery(Employee.class);
Expression startExpr = expressionBuilder.get("id").equal(new Integer(1));
Expression connectBy = expressionBuilder.get("managedEmployees");
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 will generate the following SQL:
SELECT * FROM EMPLOYEE START WITH ID=1 CONNECT BY PRIOR ID=MANAGER_ID ORDER SIBLINGS BY LAST_NAME, FIRST_NAME