我使用Hibernate 3.6和MSSQL 2012HQL隐式连接在where子句中产生交叉连接,而不是内部联接
在执行这个HQL
select tbl.state from Property tbl where tbl.state = 1 and tbl.entity.state = 1 and
tbl.entity.className = 'com....' and tbl.fieldName = 'fieldName'
我得到这个SQL
select property0_.State as col_0_0_ from Properties property0_ cross join Entities
entity1_ where property0_.refEntityid=entity1_.id and property0_.State=1 and
entity1_.State=1 and entity1_.ClassName='com....' and property0_.FieldName='fieldName'
*请注意交叉连接和在where子句中添加了条件。
根据Hibernate的文档https://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html#queryhql-joins-forms
隐含的加入应该产生于内加入。
我注意到有一个开放的错误https://hibernate.atlassian.net/browse/HHH-7707可能是指这个问题,但没有人回答,它已经打开了一年。
我很感谢这个问题的任何信息。谢谢。
PS。我很清楚,使用隐式连接不是编写HQL的正确方式,但我现在无法对此做任何事情。
哇,这真的很蹩脚,在休眠的部分破碎。 '如果foo.bar不为空或foo.bar.baz = x'返回一个完全不合逻辑的零结果,如果所有的foo对象都有一个空栏参考... – Gus