ERROR 1054 (42S22): Unknown column ... in ' ON clause '
Reason:
To MySQL5.0 a Bug, enclose the combined table in parentheses :
Example :
SQL code
- select ( c.id, a.id, b.id) from a a, b b left join c c on c.a_id = a.a_id and c.b_id = b.b_id
The execution of this sentence should be error-free, but MySQL 5 execution will go wrong.
Because there is a bug under MySQL, it is necessary to enclose the combined table in parentheses:
SQL code
- select ( c.id, a.id, b.id) from (A  A, B B) left join c c on c.a_id = a.a_id and c.b_id = b.b_id
But HQL generation is such a statement, how to do? We can change the way HQL is written to generate another SQL statement to avoid errors in this bug
Turn select (C.id, a.ID, b.id) from c c to left join C.A A to a left join C.B b
It will generate
SQL code
- SELECT (c.id, a.ID, b.id) from a-a left join B-B left join C-C on c.a_id = a.a_id and c.b_ id = b.b_id
In this case, MySQL will not go wrong.
MySQL 1054 Error Unknown column ... in ' ON clause '