我正在使用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'
Run Code Online (Sandbox Code Playgroud)
我得到这个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'
Run Code Online (Sandbox Code Playgroud)
*注意where子句中的交叉连接和添加条件.
根据Hibernate docs 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子句中添加条件:
where property0_.refEntityid=entity1_.id
Run Code Online (Sandbox Code Playgroud)
而不是用它
inner join Entities entity1_ on property0_.refEntityid=entity1_.id
Run Code Online (Sandbox Code Playgroud)
结果完全一样.
在HQL中使用隐式连接根本不是问题,只要您了解他们正在做什么.
| 归档时间: |
|
| 查看次数: |
10853 次 |
| 最近记录: |