I have a problem with creating a query in JPQL
to join two tables Table1
and Table2
by a field called code
(make LEFT JOIN
).
The problem is that my two entities don't have the relations with JPA (and I need to do it that way).
I searched for a solution but I have not found it yet.
You can have the entity manager perform a native query. See this page section "Utilizing Native SQL Queries"
So your code would look like this:
List<SOME_DATA_TYPE> list = (List<SOME_DATA_TYPE>)em.createNativeQuery
("SELECT * FROM table1 a join talbl2 b on a.somefiedd = b.somefield " , some.package.name.SOME_DATA_TYPE.class)
.getResultList();
Technically not JPQL but still JPA. It's an idea. Hope that helps.
如果您没有使用正确的实体关系,则不能使用JPQL,但您可以使用本机查询,考虑使用它们来解决您的需求。
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.