Community
Participate
Working Groups
Build Identifier: 2.1.2 Forum post: http://www.eclipse.org/forums/index.php?t=msg&th=203591&start=0&S=4ed628cf51810b529364ad539df555fb When setting up a query using an expression build like (parentBuilder is the main expression builder for this query): ExpressionBuilder parentBuilder = new ExpressionBuilder(); ExpressionBuilder childBuilder = new ExpressionBuilder(); ReportQuery subQuery = new ReportQuery(DomainObject.class, childBuilder); Expression startWith = childBuilder.equal(parentBuilder.get("parent")); Expression connectBy = childBuilder.get("children"); subQuery.setHierarchicalQueryClause(startWith, connectBy, null); subQuery.addAttribute("oid"); return parentBuilder.notExists(subQuery); I expect the resultant sql to look like: SELECT t0.* FROM DOMAIN_OBJECT t0 WHERE NOT EXISTS (SELECT t1.OID FROM DOMAIN_OBJECT t1 START WITH t1.OID = t0.PARENT_OID CONNECT BY t1.PARENT_OID = PRIOR t1.OID); However, the generated sql ends up using the wrong alias (t1) in the start with clause: SELECT t0.* FROM DOMAIN_OBJECT t0 WHERE NOT EXISTS (SELECT t1.OID FROM DOMAIN_OBJECT t1 START WITH t1.OID = t1.PARENT_OID CONNECT BY t1.PARENT_OID = PRIOR t1.OID); This appears to be caused by the normalization of the start with expression - an assumption is made that all portions of the expression should be built on the expression builder for the sub query, which isn't true in this case. Reproducible: Always Steps to Reproduce: 1. Execute a query using the expression as described above.
What happens if you change your code as follows: ExpressionBuilder parentBuilder = new ExpressionBuilder(DomainObject.class); ExpressionBuilder childBuilder = new ExpressionBuilder(DomainObject.class);
(In reply to comment #1) > What happens if you change your code as follows: > > ExpressionBuilder parentBuilder = new ExpressionBuilder(DomainObject.class); > ExpressionBuilder childBuilder = new ExpressionBuilder(DomainObject.class); Tried this, the end result is the same. Line 1277 in SQLSelectStatement seems to be the culprit: startWithExpression = getStartWithExpression().rebuildOn(builder); When normalize is called for the subquery, the entire start with expression gets rebuilt on the childBuilder clone. This includes the expressions that were built using the parentBuilder.
Setting target and priority. See the following page for the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink