无法使用JOIN查询实体

时间:2018-10-09 17:52:24

标签: hibernate intellij-idea hql

我正在努力弄清 HQL ,并在IntelliJ IDEA的Persistence窗口中运行它。

这就是问题:我可以运行像这样的简单查询:

hql> SELECT offer FROM OfferEntit offer;
hql> SELECT offer FROM OfferEntit offer WHERE offer.id = 1L; 

但是如果我添加类似JOIN的内容:

hql> SELECT offer FROM OfferEntit offer 
     JOIN offer.owner AS owner WHERE owner.id = 1L;

我得到一个空结果。总是。不管我做什么。我不知道为什么。


  • 我检查了这些记录是否存在-是的
  • 我没有收到任何错误日志

1 个答案:

答案 0 :(得分:0)

您可以尝试左联接还是联接提取

SELECT offer FROM OfferEntit offer 
 LEFT JOIN offer.owner AS owner WHERE owner.id = 1L

SELECT offer FROM OfferEntit offer 
 JOIN FETCH offer.owner AS owner WHERE owner.id = 1L