QuerySyntaxException "with-clause expressions did not reference from-clause element to which the with-clause was associated"

Description

In Version 3.1.2 the following "EventManager" HQL query worked fine:

select p from Person p join p.emailAddresses as email with email = 'xyz'

and produced an SQL query like this:

select person0_.PERSON_ID as PERSON1_2_, person0_.age as age2_, person0_.firstname as firstname2_, person0_.lastname as lastname2_
from PERSON person0_
inner join PERSON_EMAIL_ADDR emailaddre1_
on person0_.PERSON_ID=emailaddre1_.PERSON_ID and (emailaddre1_.EMAIL_ADDR='xyz')

From Version 3.1.3 on this HQL throws the following QuerySyntaxException:
"with-clause expressions did not reference from-clause element to which the with-clause was associated"

Attachments

2

Activity

Show:

Steve Ebersole June 2, 2009 at 5:41 PM

Applied your patch Oleg. Thanks!

Oleg Golberg June 1, 2009 at 9:28 PM

Sorry, here is the correct patch. Please ignore my previous attachment.

Oleg Golberg June 1, 2009 at 9:20 PM

Attached is a patch for HqlSqlWalker that fixes this bug. The patch is made against 3.3.1 but also applies to trunk.

Mike Ressler December 4, 2008 at 8:58 AM

Spoke too soon. The generated SQL doesn't include the with clause at all, all my data was messed up:

HQL:
select person, count(data.referenceMe) from model.DataAboutPerson as data right join data.whoImAllAbout as person with (data.referenceMe like 'me%')

SQL:
select person1_.person as col_0_0_, count(dataaboutp0_.referenceme) as col_1_0_, person1_.person as person1_, person1_.name as name1_ from dataaboutperson dataaboutp0_ right outer join people person1_ on dataaboutp0_.person=person1_.person

The ON keyword exists, but the "like 'me%'" information is lost. Looks like I'll need to dig deeper into the SQL generation code to find where the info is lost. The log4j debug logs don't seem to be leading me in any particular direction.

Anyone watching this bug that can point me in the right direction in the SQL generation code? Or anyone that might know the underlying reason why this isn't supported already?

Antonio Juarez December 4, 2008 at 8:43 AM

I don't think we can just comment the lines out - there should be some kind of restriction on this WITH part of the query. It doesn't need to reference the right-hand side, but I believe it should reference either the right-hand or the left-hand side of the query, and that does call for some validation. Maybe the if() condition could be replaced by something like:

if ( referencedFromElement

=leftHandSideFromElement) {
throw new InvalidWithClausException(......);
}

IMO

Fixed

Details

Assignee

Reporter

Components

Priority

Created July 21, 2006 at 2:52 PM
Updated June 2, 2009 at 5:41 PM
Resolved June 2, 2009 at 5:41 PM