How to left join unrelated entities?

蓝咒 提交于 2019-12-10 02:30:48

问题


When i try to run a query like this:

QA A = QA.a;
QB B = QB.b;
...
from(A)
.leftJoin(B).with(B.name.eq(A.nameSomething));

(A and B entities are not related) I'm always getting this error:

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

I would like to be able to left join unrelated entities using querydsl. Is it possible at all? Or the only way is to write a native Oracle query?


回答1:


Joining unrelated entities is not possible with Querydsl JPA. Querydsl JPA uses JPQL internally and inherit's this restriction.




回答2:


Assuming you're referring to JPA Criteria. innerJoin, leftOuterJoin are for joining relationships, since that is the only logical thing you would join on in an O-O system.

If instead you want to compare equality of entity.field with entity2.field (where no FK exists in the database and no relation exists in the classes) then do that in the WHERE clause, just like any filter.

Obviously QueryDSL has its own syntax/rules so if referring to that then this is not JPA



来源:https://stackoverflow.com/questions/25848994/how-to-left-join-unrelated-entities

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!