-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: NHibernate Join Syntax And SQL Server Issues
PostPosted: Fri May 04, 2007 7:26 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
I've noticed that in certain situations NHibernate will create a cross join (by using a comma in the from clause) and then filter the join in the where clause. This does seem defensible.

Lately I have seen errors (with certain generated queries) where I receive an error stating "unable to bind multi-part alias..." referring to an alias an id which is complete valid in the SQL statement (or at least appears to be to my eyes). I was able to play with the HQL in such a way that the generated SQL changed and started working.

It now appears that SQL Server 2000/2005 have a bug where if you use a comma in the join clause you can not separate an aliased table and another table from each other with a comma joined table in between. So for example

Code:
SELECT * FROM A, B INNER JOIN C ON A.Id = C.Id WHERE B.Id = A.SubId


would be an invalid SQL statement according to SQL Server whereas

Code:
SELECT * FROM A INNER JOIN C ON A.Id = C.Id, B WHERE B.Id = A.SubId


would be totally valid. Upon further investigation it turns out that the comma is in fact the root cause of the issue. Simply changing the first query to the following resolved the issue:

Code:
SELECT * FROM A CROSS JOIN B INNER JOIN C ON A.Id = C.Id WHERE B.Id = A.SubId


So in short isn't it a good idea to use the cross join syntax instead of the comma, or at least do this for Sql Server 2000/2005? I took a look at the NHibernate source code and it looks like it is a super easy change. I would be willing to make the change and submit it if that is desired.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 7:51 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, submit it to JIRA please (once it's back online).


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 1:21 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
http://jira.nhibernate.org/browse/NH-1014


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.