How to make left join in Hibernate Query Language?

This is my HQL query, but it does not work and throws an error.

Hql request:

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

and causes this error:

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

How can I solve this problem? In fact, I got the value from more than one table. This query does not work with CreateQuery(strQuery) .

+6
source share
1 answer

In HQL, you can use LEFT JOIN only with a related property in the main entity:

Example

EntityA has an entityB of type EntityB so you can

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

IF EntityA does not have an entityB property, but EntityB has an entityA property, you cannot write this:

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

because you have a mistake. This is a sleep issue that has not yet been resolved.

+10
source

Source: https://habr.com/ru/post/952865/


All Articles