oracle 如何在 Hibernate 查询语言中执行左连接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18545390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:15:32  来源:igfitidea点击:

How to perform left join in Hibernate Query Language?

oraclehibernatehql

提问by karthik.A.M

This is my HQL query, but it isn't working and is throwing an error.

这是我的 HQL 查询,但它不起作用并引发错误。

Hql query:

后台查询:

SELECT 
    *
FROM 
    TABLEA A 
LEFT JOIN 
    A.TABLEB B 
WHERE 
    A.COLUMNNAME = B.COLUMNAME

and it causes this error:

它会导致此错误:

org.hibernate.QueryException:
This Query caught Exception. could not resolve property: of TABLEB:TABLEA.

How can I solve this problem? Actually I retrieved a value from more than one table. This query doesn't work with CreateQuery(strQuery).

我怎么解决这个问题?实际上,我从多个表中检索了一个值。此查询不适用于CreateQuery(strQuery).

回答by Joe Taras

In HQLyou can use LEFT JOINonly with linked property in main entity:

HQLLEFT JOIN只能与主实体中的链接属性一起使用:

Sample

样本

EntityA has an object entityB of type EntityB so you can

EntityA 有一个 EntityB 类型的对象 entityB,因此您可以

SELECT A FROM EntityA A LEFT JOIN A.entityB B WHERE ...

IF EntityA haven't entityB property but is EntityB have a property entityA, you can't write this:

如果 EntityA 没有 entityB 属性但 EntityB 有一个属性 entityA,则不能这样写:

SELECT A FROM EntityA LEFT JOIN EntityB B WHERE B.entityA = A 

because you have an error. This is an Hibernate issue not resolved yet.

因为你有错误。这是一个尚未解决的休眠问题。