Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Correlated ReportQuery using wrong alias in start with clause
Correlated ReportQuery using wrong alias in start with clause [message #650881] Thu, 27 January 2011 00:35 Go to next message
Will Butler is currently offline Will ButlerFriend
Messages: 4
Registered: January 2011
Junior Member
I have a domain object that has a parent child relationship. I am setting up a query that returns objects that don't have any children (recursively) that satisfy a particular condition. The code below is not exactly what I am doing, but it is close enough to illustrate my issue:

        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);


As you can see, I am using two separate expression builders to set up the correlated subquery. I expect the generated sql to look something 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);


I assume this is a bug, but I'm not sure if I am doing something incorrectly. Has anyone seen anything like this? Any known work arounds?

Thanks!

Will

Re: Correlated ReportQuery using wrong alias in start with clause [message #651031 is a reply to message #650881] Thu, 27 January 2011 14:14 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello Will,

As the Subquery is using the parentBuilder, how are you getting this expressionBuilder into the main query? The problem is likely that the parentBuilder isn't associated to main query and since it doesn't have a class, EclipseLink is fixing it so that it refers to the same t1 as childBuilder (instead of creating a new t2 for it, which would also be wrong).

The subquery needs to use the ExpressionBuilder from the main query as the parentBuilder, so that it is associated to the same DOMAIN_OBJECT as used in the main query.

Best Regards,
Chris
Re: Correlated ReportQuery using wrong alias in start with clause [message #651043 is a reply to message #651031] Thu, 27 January 2011 14:45 Go to previous message
Will Butler is currently offline Will ButlerFriend
Messages: 4
Registered: January 2011
Junior Member
The code snippet doesn't make it particularly clear, but the "parentBuilder" is, in fact, the builder associated with the main query. To further illustrate the issue, if I call subQuery.setSelectionCriteria with the "startWith" expression, the where clause contains the expression (t1.OID = t0.PARENT_OID) with the proper alias.

- Will

[Updated on: Thu, 27 January 2011 14:48]

Report message to a moderator

Previous Topic:@postload problem : never called
Next Topic:Unresolved generator name "foreign" ?
Goto Forum:
  


Current Time: Thu Apr 18 07:49:09 GMT 2024

Powered by FUDForum. Page generated in 0.01807 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top