HQL,左连接在同一张桌子上 [英] HQL, left join on the same table

查看:155
本文介绍了HQL,左连接在同一张桌子上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的查询



pre> FROM Tvshow e
LEFT JOIN Tvshow e1 ON e1.num = e.num
WHERE e1.code ='024'
AND e.code不是空的
AND e.code!='024'

Hibernate看起来不像如果你有两个实体之间的关联,只有在HQL中的左连接是可能的。

由于您的查询将联接的实体强制为非空,所以内部联接会执行相同的操作。只有在两个实体之间存在关联的情况下,也可以使用连接语法进行内部连接。但你可以通过在where子句中添加一个相等性测试来完成:

 从Tvshow e中选择e,Tvshow e1 
其中e.num = e1.num
和e1.code ='024'
和e.code不为空
和e.code!='024'


I search a way to do a left join with the same table with hql.

It's my query

  FROM Tvshow e
  LEFT JOIN Tvshow e1 ON e1.num = e.num
 WHERE e1.code = '024'
   AND e.code is not null
   AND e.code != '024'

Hibernate don't seem to like on operator.

解决方案

Left joins in HQL are only possible if you have an association between two entities. Since your query imposes the joined entity to be non null, an inner join would do the same thing. An inner join, with the join syntax, is also possible only if you have an association between two entities. But you can do it by simply adding an equality test in the where clause:

select e from Tvshow e, Tvshow e1
where e.num = e1.num
and e1.code = '024'
and e.code is not null
and e.code != '024'

这篇关于HQL,左连接在同一张桌子上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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