Reputation: 2201
I am using JPA (Hibernate)
in my project and can't write JOIN
queries without explicitly setting a relationship between Entities
.
I remember doing same thing in TOPLINK
.
Query:
Example 1:
SELECT a FROM
EntityA a
INNER JOIN EntityB b on b.col1=a.col1
INNER JOIN EntityC c on c.col1=b.col1
LEFT JOIN EntityC c on c.col1=a.col1
Error:
Unexpected token "on"
Example 2:
SELECT a FROM
EntityA a
INNER JOIN EntityB b
INNER JOIN EntityC c
LEFT JOIN EntityC c
WHERE b.col1=a.col1 AND c.col1=b.col1 AND c.col1=a.col1
Error:
ERROR o.hibernate.impl.SessionFactoryImpl - Error in named query:
org.hibernate.hql.ast.QuerySyntaxException: Path expected for join!
[SELECT **MY QUERY HERE**]
at org.hibernate.hql.ast.QuerySyntaxException.convert
(QuerySyntaxException.java:54)
~[hibernate3.jar:na]
ERROR org.hibernate.hql.PARSER - Path expected for join!
ERROR org.hibernate.hql.PARSER - Invalid path: 'b.col1'
ERROR org.hibernate.hql.PARSER - Invalid path: 'c.col1'
Please do not pay too much attention on Entity and Column names as they are not actual names ofcourse :)
Thanks for your time.
Upvotes: 0
Views: 3928
Reputation: 42114
Normal joins cannot be used if there is no association in model. If there actually is association, it makes sense to add it also to model.
If that is not an option, you can go for cross joins (which affects values in select list) in HQL:
FROM A as a, B as b WHERE b.col1=a.col1
Other approaches can be found from here.
Upvotes: 3