QuerySpec queryspec = new QuerySpec(PBIResourceCategory.class);
queryspec.setAdvancedQueryEnabled(true);
QuerySpec subQueryspec = new QuerySpec();
int parentIndex = subQueryspec.appendClassList(ResourceCategory.class, false);
int linkIndex = subQueryspec.appendClassList(ResourceCategoryLink.class, false);
int childIndex = subQueryspec.appendClassList(ResourceCategory.class, false);
subQueryspec.appendSelect(new ClassAttribute(ResourceCategory.class,
ResourceCategory.RESERV1), new int[] { childIndex }, false);
WhereExpression where = new SearchCondition(ResourceCategory.class,
ResourceCategory.RESERV1, "=", reserv1);
subQueryspec.appendWhere(where, new int[] { parentIndex });
subQueryspec.appendJoin(linkIndex, ResourceCategoryLink.CATEGORY_ROLE, parentIndex);
subQueryspec.appendJoin(linkIndex, ResourceCategoryLink.SUB_CATEGORY_ROLE, childIndex);
ClassAttribute pbiID = new ClassAttribute(PBIResourceCategory.class,
PBIResourceCategory.PBI_ID);
where = new SearchCondition(pbiID, SearchCondition.IN, new SubSelectExpression(
subQueryspec));
queryspec.appendWhere(where, new int[]{0});
QueryResult result = PersistenceHelper.manager.find((StatementSpec) queryspec);