简体   繁体   English

HQL,左连接在同一个表上

[英]HQL, left join on the same table

I search a way to do a left join with the same table with hql. 我搜索一种方法与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. Hibernate似乎不喜欢运营商。

Left joins in HQL are only possible if you have an association between two entities. 只有在两个实体之间存在关联时,才能在HQL中进行左连接。 Since your query imposes the joined entity to be non null, an inner join would do the same thing. 由于您的查询将联接实体强制为非null,因此内部联接将执行相同的操作。 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: 但是你可以通过在where子句中添加相等性测试来实现:

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'

I don't use hibernate but, judging by this example: 我不使用hibernate但是,通过这个例子来判断:

from Cat as cat
inner join cat.mate as mate
left outer join cat.kittens as kitten

From this page: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html#queryhql-joins-forms 从这个页面: http//docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html#queryhql-joins-forms

It looks like you just don't do an ON? 看起来你只是不做ON? Let me know if I'm mistaken and I'll take this down. 让我知道如果我弄错了,我会把它拿下来。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM