【问题标题】:JOIN with multiple OR in HQL在 HQL 中加入多个 OR
【发布时间】:2021-01-27 01:39:10
【问题描述】:

下面是一个带有多个连接和条件的 SQL 查询,它给出了所需的输出,我想将下面的查询转换为 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

【问题讨论】:

  • 能否请您向我们展示您到目前为止所做的尝试?
  • 到目前为止我已经做了很多选择 c.name from customer c join c.custGeoRel cg join cg.geography g join g.geographyCategory gc join g.geographyHierarchy gghCluster join gghCluster.parentGeography gghDivision join g。 roleDataRelList rdr

标签: java sql hibernate hql nativequery


【解决方案1】:

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

【讨论】:

  • 我们可以使用 join 添加带有 Collection 属性的 ON 子句吗?
  • 是的,你可以。只需尝试一下,自己看看它是否有效。
  • 我们可以在集合属性中添加 ON 子句吗?如果是,那么如何?
  • 什么是你不明白的?就像例如那样做select ... from Entity e join e.myCollection c on c.attr = 1
猜你喜欢
  • 2011-09-14
  • 2017-08-28
  • 2018-06-12
  • 2012-10-15
  • 2010-11-01
  • 2013-02-07
  • 2016-06-24
  • 1970-01-01
  • 2013-09-10
相关资源
最近更新 更多