HQL with joins in sub-select creates wrong SQL

Description

The following query is translated to wrong SQL - the join is missing from the sub-select:

(The query was created by a HQL generator of ours - hence the superfluous parentheses). The exceotion is:

NHibernate.Exceptions.GenericADOException : could not execute query
[ select sheet0_.Id as Id2_, sheet0_.Name as Name2_, sheet0_.Folder as Folder2_ from Sheet sheet0_ where (exists (select shelf1_.Id from Shelf shelf1_ where folder2_.Shelf=shelf1_.Id and shelf1_.Id=1)) and sheet0_.Name='SomeName' ]
[SQL: select sheet0_.Id as Id2_, sheet0_.Name as Name2_, sheet0_.Folder as Folder2_ from Sheet sheet0_ where (exists (select shelf1_.Id from Shelf shelf1_ where folder2_.Shelf=shelf1_.Id and shelf1_.Id=1)) and sheet0_.Name='SomeName']
----> System.Data.SqlClient.SqlException : The multi-part identifier "folder2_.Shelf" could not be bound.

Since NHib 0.99 and in Hibernate, it has been possible to use joins inside subqueries. HQL allows it, and therefore, it should produce correct SQL (both syntactically and semantically). Actually, joins in subqueries are necessary if there are OR or NOT operators inside the subquery (some simpler queries can be rewritten with all Joins at top-level).

I consider this bug critical because there is no workaround for

  • HQL generated for earlier NHib versions

  • manual HQL that needs OR or NOT inside a subquery

  • (I assume) the correct translation of Linq's .Any in the NHib.Linq provider

I have attached a test case that shows the behavior.

Environment

None

Assignee

Unassigned

Reporter

Harald M. Müller

Labels

Components

Affects versions

Priority

Major
Configure