我遇到Hibernate生成无效sql的问题.具体来说,混合和匹配隐式和显式连接.这似乎是一个
open bug.
但是,我不确定为什么这是无效的sql.我想出了一个生成相同语法异常的小玩具示例.
架构
CREATE TABLE Employee ( employeeID INT,name VARCHAR(255),managerEmployeeID INT )
数据
INSERT INTO Employee (employeeID,name) VALUES (1,'Gary') INSERT INTO Employee (employeeID,name,managerEmployeeID) VALUES (2,'Bob',1)
工作sql
这两个查询都有效.我意识到有笛卡尔积;那是故意的.
显式加入:
SELECT e1.name,e2.name,e1Manager.name FROM Employee e1 CROSS JOIN Employee e2 INNER JOIN Employee e1Manager ON e1.managerEmployeeID = e1Manager.employeeID
隐含的JOIN:
SELECT e1.name,e1Manager.name FROM Employee e1,Employee e2,Employee e1Manager WHERE e1.managerEmployeeID = e1Manager.employeeID
无效的sql
SELECT e1.name,Employee e2 INNER JOIN Employee e1Manager ON e1.managerEmployeeID = e1Manager.employeeID
在MS2000中,我收到错误:
The column prefix ‘e1’ does not match
with a table name or alias name used
in the query.
Unknown column ‘e1.managerEmployeeID’
in ‘on clause’.
问题(S)
>为什么这种语法无效?
> Bonus:有没有办法强制Hibernate只使用显式JOIN?