JPA多次连接 [英] JPA multiple joins
本文介绍了JPA多次连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些课程
class Project {
@ManyToOne Company owner;
@ManyToMany Set<Person> resources;
}
class Company {
@ManyToOne Country country;
}
class Person {
}
我如何编写JPQL以获得在特定国家/地区的公司的项目中使用的所有资源?
How can I write a JPQL to get the all the resources working on projects for companies in a specific country?
下面的那个似乎不起作用(使用DataNucleus)
The one below doesn't seem to work (using DataNucleus)
SELECT r FROM Project p JOIN p.resources r JOIN p.owner c WHERE c.country = :country
它尝试将r
与c
联接,并且当然不具有owner
属性,并且在DataNucleus内部引发了NullPointerException.
It tries to join r
with c
and of course does not have the owner
property and a NullPointerException is raised inside DataNucleus.
推荐答案
这应该可以完成您期望的操作:
This should do what you expect:
SELECT resource FROM Project p INNER JOIN p.resources as resource
我忘记了最初问题的一部分:
I forgot a part of the initial question:
SELECT resource FROM Project p INNER JOIN p.resources as resource where p.owner.country = :country
这篇关于JPA多次连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文