In SQL-92 joins performed in the where clause (comma operator in from clause) and joins performed in the from clause (join keyword) had the same precedence. SQL-99 clarified this such that the from clause joins had higher precedence.
Hibernate currently treats these as having the same precedence.
A good explanation comes from the MySQL docs ( http://dev.mysql.com/doc/refman/5.0/en/join.html ) :
Previously, the comma operator (,) and JOIN both had the same precedence, so the join expression t1, t2 JOIN t3 was interpreted as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the expression is interpreted as (t1, (t2 JOIN t3)). This change affects statements that use an ON clause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are.
CREATE TABLE t1 (i1 INT, j1 INT);
CREATE TABLE t2 (i2 INT, j2 INT);
CREATE TABLE t3 (i3 INT, j3 INT);
INSERT INTO t1 VALUES(1,1);
INSERT INTO t2 VALUES(1,1);
INSERT INTO t3 VALUES(1,1);
SELECT * FROM t1, t2 JOIN t3 ON (t1.i1 = t3.i3);
Previously, the SELECT was legal due to the implicit grouping of t1,t2 as (t1,t2). Now the JOIN takes precedence, so the operands for the ON clause are t2 and t3. Because t1.i1 is not a column in either of the operands, the result is an Unknown column 't1.i1' in 'on clause' error. To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for the ON clause are (t1,t2) and t3:
SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);
Alternatively, avoid the use of the comma operator and use JOIN instead:
SELECT * FROM t1 JOIN t2 JOIN t3 ON (t1.i1 = t3.i3);
This change also applies to statements that mix the comma operator with INNER JOIN, CROSS JOIN, LEFT JOIN, and RIGHT JOIN, all of which now have higher precedence than the comma operator.
so basically i added this with a hook into the dialect that ask the dialect for its cross join separator. The default now returns " cross join ". As we find databases which do not support from-clause joins or do not support "A cross join B" specifically we can change their dialects.
Gonna resolve this, not close it. Please test it out. Thanks!
Under PostgreSQL this change causes many problems for us. We were tracking the milestone releases and found that between M1 and M2+ a lot of queries blowing out the server and running for 14+ days before they were noticed.
Has anyone on the Hibernate team seem this under PostgreSQL ( 8.3/8.4 ) - we're using the org.hibernate.dialect.PostgreSQLDialect dialect.
Replacing "," with "cross join" causes a lot of issues. Not only "cross join" is not supported in many DB engines but "," and "cross join" are NOT equivalent, changing one with another changes the precedence of other joins, and precedence is important for outer joins.
This is detailed in
Bulk closing stale resolved issues