简体   繁体   中英

Hibernate left join between independent tables - org.hibernate.hql.ast.QuerySyntaxException Path expected for join

I have some tables listed in persistence.xml as:

<persistence-unit name="myEntityManager" transaction-type="RESOURCE_LOCAL">  
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
   <class>com.myPackage.someTable</class>
   <class>com.myPackage.tableOne</class>
   <class>com.myPackage.tableTwo</class>
   <class>com.myPackage.tableThree</class>
   <class>com.myPackage.tableThreePK</class>
   <class>com.myPackage.tableFour</class>
</persistence-unit>

Thus the classes are independent of each other. No relationships defined between them.

I have a sql query as below:

select s.* from someTable s 
join tableOne O on s.col1 = O.col1 
join tableTwo T on s.col2 = T.col2 
join tableThree Th on s.col3 = Th.col3 and s.col4 = Th.col4 
left join tableFour f on s.col6 = F.col6 
where s.col5 = 'abc'

How to write this query in hibernate for above scenario:

select s.* from someTable s 
join tableOne O  
join tableTwo T  
join tableThree Th 
left join tableFour f 
where s.col5 = :col5 
and s.col1 = O.col1 
and s.col2 = T.col2 
and s.col3 = Th.pk.col3 and s.col4 = Th.col4 
and s.col6 = F.col6 

myQuery.setParameter("col5", "abc");

Above query doesn't work and gives

org.hibernate.hql.ast.QuerySyntaxException: Path expected for join!

What is the issue ? What am I missing ?

Thanks for reading!

HQL doesn't support left joins without associations between entities. You'll have to use a SQL query to do that.

Side note: select s.* isn't valid HQL. select s is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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