HQL在where子句中隐式连接生成交叉连接而不是内部连接 [英] HQL implicit join in where clause generate cross join instead of inner join

查看:106
本文介绍了HQL在where子句中隐式连接生成交叉连接而不是内部连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当执行这个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子句中的交叉连接添加条件

根据Hibernate docs href =https://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html#queryhql-joins-forms =noreferrer> https://docs.jboss。组织/休眠/核心/ 3.5 /参考/ EN / HTML / queryhql.ht ml#queryhql-joins-forms



隐式连接应该生成内部连接

我注意到有一个开放的错误 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆