Bug 335622 - Correlated ReportQuery using wrong alias in start with clause
Summary: Correlated ReportQuery using wrong alias in start with clause
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-27 16:18 EST by Will Butler CLA
Modified: 2022-06-09 10:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Will Butler CLA 2011-01-27 16:18:23 EST
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.
Comment 1 Tom Ware CLA 2011-02-03 10:00:07 EST
What happens if you change your code as follows:

ExpressionBuilder parentBuilder = new ExpressionBuilder(DomainObject.class);
ExpressionBuilder childBuilder = new ExpressionBuilder(DomainObject.class);
Comment 2 Will Butler CLA 2011-02-03 10:11:38 EST
(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.
Comment 3 Tom Ware CLA 2011-02-10 09:09:39 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:30:40 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink