【发布时间】:2013-12-13 00:08:19
【问题描述】:
我正在使用 Hibernate 3.6 和 MSSQL 2012。
执行此 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 子句中的 cross join 和 add 条件。
根据 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 的正确方法,但我现在对此无能为力。
【问题讨论】:
-
哇,这在休眠方面真的很蹩脚和坏掉了。
where foo.bar is not null or foo.bar.baz = x如果所有 foo 对象都有一个空 bar 引用,则返回完全不合逻辑的零结果...