使用HQL进行多个OR条件的JOIN操作。

huangapple go评论69阅读模式
英文:

JOIN with multiple OR in HQL

问题

以下是一个带有多个连接和条件的SQL查询,可以得到所需的输出。我想将下面的查询转换为HQL。

select c from Customer c
join CustomerGeoRel cg on c.id = cg.customerId
join Geography g on cg.geoId = g.id
join GeoGeoHierarchy gghCluster on g.id = gghCluster.geoId
join GeoGeoHierarchy gghDivision on gghCluster.geoId = gghDivision.parentGeoId
join RoleDataRel rdr on gghCluster.geoId = rdr.permissionDataId or
gghDivision.parentGeoId = rdr.permissionDataId or
g.id = rdr.permissionDataId
英文:

Below is a SQL query with multiple joins and conditions which gives the desired output, I want to convert the below query to HQL

select * from customer c 
join customer_geo_rel cg on c.id=cg.customer_id
join geography g on cg.geo_id=g.id   
join geo_geo_hierarchy gghCluster on g.id = gghCluster.geo_id
join geo_geo_hierarchy gghDivision on gghCluster.geo_id = gghDivision.parent_geo_id   
join role_data_rel rdr on gghCluster.geo_id = rdr.permission_data_id OR   
gghDivision.parent_geo_id = rdr.permission_data_id OR   
g.id=rdr.permission_data_id

答案1

得分: 0

什么是问题?HQL支持用于连接的ON子句,如果您使用的是非常旧的Hibernate版本,您可以使用类似于.. join g.roleDataRelList rds on ...的WITH子句。

英文:

What's the problem? HQL supports the ON clause for joins and if you use a very old version of Hibernate, you can use the WITH clause like e.g. .. join g.roleDataRelList rds on ...

huangapple
  • 本文由 发表于 2020年10月13日 01:54:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/64322969.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定