HQL在where子句中隐式连接生成交叉连接而不是内部连接 [英] HQL implicit join in where clause generate cross join instead of inner join
问题描述
当执行这个HQL时
从属性tbl中选择tbl.state,其中tbl.state = 1和tbl.entity.state = 1和
tbl.entity.className ='com ....'和tbl.fieldName = 'fieldName'
我得到这个SQL
从属性property0选择property0_.State作为col_0_0_交叉连接实体
entity1_其中property0_.refEntityid = entity1_.id和property0_.State = 1和
entity1_。 State = 1和entity1_.ClassName ='com ....'和property0_.FieldName ='fieldName'
<请注意where子句中的交叉连接和添加条件。
隐式连接应该生成内部连接。
我注意到有一个开放的错误 https://hibernate.atlassian .net / browse / HHH-7707 ,可能是指这个问题,但没有人回答,它已经打开了一年。
关于这个问题的信息。谢谢。
PS。我很清楚,使用隐式连接不是编写HQL的正确方式,但我现在无法对此做任何事情。 解决方案
您的连接是一个内部连接,但使用在where子句中添加条件的旧语法:
其中property0_.refEntityid = entity1_.id
而不是
内部连接实体entity1_ on property0_.refEntityid = entity1_.id
结果完全相同。
在HQL中使用隐式连接并不是一个问题,只要您明白他们的重新做。
I'm using Hibernate 3.6 and MSSQL 2012.
When executing this 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'
I'm getting this 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'
*Notice the cross join and the added condition in the where clause.
According to Hibernate docs https://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html#queryhql-joins-forms
implicit join should generate to inner join.
I've noticed that there is an open bug https://hibernate.atlassian.net/browse/HHH-7707 that may be referring to this problem but no one answered and it's opened for a year already.
I would appreciate any information about this issue. Thank you.
PS. I'm well aware that using implicit joins is not the right way of writing HQL but I can't do anything about this right now.
Your join is an inner join, but using the old syntax consisting in adding a condition in the where clause:
where property0_.refEntityid=entity1_.id
instead of doing it with
inner join Entities entity1_ on property0_.refEntityid=entity1_.id
The result is exactly the same.
And using implicit joins in HQL is not a problem at all, as long as you understand what they're doing.
这篇关于HQL在where子句中隐式连接生成交叉连接而不是内部连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!