Skip to content

NH-1014 - NHibernate Cross Join Syntax Causes Issues With SQL Server 2000/2005 #1060

Closed
@nhibernate-bot

Description

@nhibernate-bot

John Chapman created an issue — 17th May 2007, 10:20:15:

See forum post: http://forum.hibernate.org/viewtopic.php?t=974101&highlight=

When using a cross join in SQL Server 2000/2005 with the comma syntax SQL Server 2005 requires that all inner joins (inner join syntax) occur directly below the table being joined to. If a comma join occurs between the table and an inner join sql server will provide a "unable to bind multi-part alias..." error.

Changing the dialect to provide ANSI compliant " CROSS JOIN " instead of " , " would resolve this issue.

Patch to come soon...


John Chapman added a comment — 17th May 2007, 17:09:35:

zip file includes a patch for the ANSIJoinFragment which should resolve this issue.


justme84 added a comment — 21st July 2007, 4:16:01:

I'm not sure if this change won't break support for other databases (Google suggests DB2 may not support cross join syntax).


justme84 added a comment — 21st July 2007, 5:41:47:

forgot to add - the way to go would be to create a special JoinFragment/ANSIJoinFragment subclass and override Dialect.CreateOuterJoinFragment() in MsSql2000Dialect to return the subclass. If you change your patch accordingly, I will apply it.


John Chapman added a comment — 25th July 2007, 18:47:11:

I attached a file containing the patch as you recommended. Note that I don't really like what I did since I changed the buffer to be protected on the ANSIJoinFragment. I wanted to preserve the existing ANSI functionality, but that required me to make the buffer protected to make it available to the new join fragment subclass. I don't believe the existing naming strategy matches the .NET standards since protected is technically aware to other assemblies which happen to inherit from that class.

I can modify the code if you would like, or we could leave it if you prefer. I also had to create a new virtual method to create an instance of itself. This is to support the Copy method so that Copy would create the correct subclass. I could have made Copy virtual and duplicated the copy code, but preferred to leave the copy code alone and make a new virtual method to create the instance of itself. This could also be changed if you wish.


R. Muti added a comment — 3rd November 2007, 23:51:59:

This is still an issue with HQL, which appears to use QueryJoinFragment instead of ANSIJoinFragment.

I tried to make a similar change to QueryJoinFragment (I just replaced ", " with " cross join "), but for some reason it translated the HQL "from ObjectA a, ObjectB" into the SQL "from cross join TableA a cross join TableB b". I'm not very familiar with the source code, so I'm not sure why this is happening.


Fabio Maulo added a comment — 15th June 2009, 20:15:06:

We can't apply the patch without some specific tests.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions