我想使用jpa标准在查询中显示父子关系。 但坚持如何设置连接表达式
ReadAllQuery raQuery = JpaHelper.getReadAllQuery(transquery);
raQuery.setHierarchicalQueryClause(startswith, connectBy, order by);
其中 transquery 来自具有多个选择和多个连接的criteriaQuery
我想将父母及其子事务显示如下,但在条件查询中使用
select t0.state,t4.name,t7.money from transaction t0 LEFT OUTER JOIN transactionAgents t4 ON (t4.TRANSID = t0.ID) LEFT OUTER JOIN AgentReference t7 on t7.id=t4.agentid where t0.transdate>'10-july-2014' and t0.circle=10 connect by prior t0.id=t0.parent ORDER BY t0.LAST_MODIFIED ASC, t0.ID DESC
答案 0 :(得分:0)
ReadAllQuery.setHierarchicalQueryClause()
是一个特定于Eclispelink的功能,此方法的javadoc提供了要传递的所有方法参数的良好描述:
Expression startWith = builder.get("id").equal(new Integer(100));
//can be any expression which identifies a set of employees
Expression connectBy = builder.get("managedEmployees");
//indicated the relationship that the hierarchy is based on, must be self-referential
Vector orderBy = new Vector();
orderBy.addElement(builder.get("startDate"));
readAllQuery.setHierarchicalQueryClause(startWith, connectBy, orderBy);
//This query would generate SQL like this:
//SELECT * FROM EMPLOYEE START WITH ID=100 CONNECT BY PRIOR ID = MANAGER_ID ORDER SIBLINGS BY START_DATE