Reputation: 17375
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!
Upvotes: 1
Views: 7641
Reputation: 691785
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.
Upvotes: 3