HQL entity aliases matching class name cause error: "DOT node with no left-hand-side!"

Description

When creating an HQL query in which the aliases in the query match the selected class names, I receive an InvalidOperationException "DOT node with no left-hand-side!" in NHibernate 2.1.2.GA.

Here is a sample query:

SELECT DISTINCT
Company AS Company,
CompanyStatus AS CompanyStatus,
CompanyAddressPrimary AS CompanyAddressPrimary
FROM Company AS Company
LEFT JOIN Company.Status AS CompanyStatus
LEFT JOIN Company.Addresses AS CompanyAddress
LEFT JOIN Company.Addresses AS CompanyAddressPrimary WITH CompanyAddressPrimary.IsPrimary = true

After being translated by NHibernate.Hql.QuerySplitter.ConcreteQueries, the resulting query is:

SELECT DISTINCT
Company AS Company,
MyNamespace.CompanyStatus AS CompanyStatus,
CompanyAddressPrimary AS CompanyAddressPrimary
FROM MyNamespace.Company AS Company
LEFT JOIN Company.Status AS CompanyStatus
LEFT JOIN Company.Addresses AS CompanyAddress
LEFT JOIN Company.Addresses AS CompanyAddressPrimary WITH CompanyAddressPrimary.IsPrimary = true

The problem is that CompanyStatus has been changed to MyNamespace.CompanyStatus in the select clause. It should look like:

Company AS Company,
CompanyStatus AS CompanyStatus,
CompanyAddressPrimary AS CompanyAddressPrimary
FROM MyNamespace.Company AS Company
LEFT JOIN Company.Status AS CompanyStatus
LEFT JOIN Company.Addresses AS CompanyAddress
LEFT JOIN Company.Addresses AS CompanyAddressPrimary WITH CompanyAddressPrimary.IsPrimary = true

The problem is that QuerySplitter.ConcreteQueries tries to replace text in the select clause with concrete class names. It should really ignore the select clause and only perform the concrete replacement in the from clause of the query. I have included a patch for this method which ignores the select clause.

I believe that this has been an issue in previous versions of NHibernate, as illustrated by this posting:
https://forum.hibernate.org/viewtopic.php?f=25&t=953844&start=0

I believe this has been corrected in Hibernate(Java) based on this posting:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-413?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#issue-tabs

I think this bug just may have been overlooked in the latest NHibernate versions, as it does look like some code has been brought over from JAVA, but it is incomplete.

It is very important for my project that the entity aliases have the most readable names possible. Attention to this patch is greatly appreciated.

Environment

None

Attachments

2

Activity

Show:

Fabio Maulo 
March 22, 2011 at 10:24 AM

Brian,
Have a look to the "Welcome" message of this site (top left corner).
It start saying:
Welcome to NHibernate's JIRA issue tracker!
If you have a bug or feature request to report, please perform a quick.....

Stephen Bohlen 
March 22, 2011 at 9:36 AM

See sample build commands.txt in the root of the nhibernate folder for details. Set the connection string appropriately and ensure that you have created a database named 'nhibernate' and the tests will take care of the rest of the setup accordingly.

Brian Gehrs 
March 22, 2011 at 9:05 AM

I can build a failing test for this, but could you provide a link or directions on how to run the existing tests? I am familiar with running NUnit tests, but it appears there may be a database that is needed need to run some of the tests. If you can point me to where I can find this database and anything else needed to run the existing tests and get them to pass, I will submit the failing test for this.

Thanks

Fabio Maulo 
October 14, 2010 at 10:18 AM

can you attach a failing test ?

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created October 7, 2010 at 12:26 PM
Updated November 20, 2014 at 9:14 AM
Who's Looking?