Uploaded image for project: 'Hibernate ORM'
  1. HHH-5352

Misleading replacement of commas with cross joins


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: 3.5.0-Beta-2, 3.5.0-Beta-3, 3.5.0-Beta-4, 3.5.0-CR-1, 3.5.0-CR-2, 3.5.0-Final, 3.5.1, 3.5.2, 3.5.3, 3.6.0
    • Fix versions: antlr-rework
    • Components: None
    • Labels:
    • Environment:
      Hibernate 3.5.3
      Ms SQL Server 2005
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
    • Sprint:


      There was a new feature implemented in 3.5.0-Beta-2: HHH-1480 Closed , as a result, for many dialects, the comma operator "," was replaced with "cross join". As it's already obvious from the feature's description, this changes join precedence. If the query contains outer joins (left or right) this replacement changes the results (because outer join precedence is important).
      This might not be interpreted as a bug if you know what SQL operator will be generated when you place a comma in HQL, but it's misleading if you don't. A HQL query like:

      select a from A a, B left join B.c c

      is not equivalent with the SQL query:

      select a.* from A.a, B b left join C c on b.cid = c.id

      because the actual SQL query is:

      select a.* from A.a cross join B b left join C c on b.cid = c.id

      The first SQL query would make a left join on B and C and then a cross join with the result and A (and this is what we should expect). The second SQL query makes a cross join on A and B and then a left join with the result and C (this is not expected since we had a comma in HQL).

      I understand the issues presented in HHH-1480 Closed , but they should be expected, i.e. a developer SHOULD expect a faliure from a query like

      select a from A a, B b join a.c C

      because "a" is not visible in the join. Hibernate should not use a cross join behind the scenes to allow such a query at the expense of providing misleading results for others.

      Maybe turn this into a feature/improvement or add another to allow explicit comma or croos join in HQL, or support parenthesis in HQL.

      The only workaround I can see for now is to re-order the query like this:

      select a from B left join B.c c, A a


          Issue links



              • Votes:
                1 Vote for this issue
                5 Start watching this issue


                • Created: