问题描述
与类似,我有这些(几乎相同)的类:
public class Project {
@ManyToMany
private Set< Person>资源;
//获取和设置资源
public class Person {
}
不同之处在于我的属性是私有的(使用bean作为实体)。
问题是:如何创建一个查询来返回所有这些确定人员的项目(在JPQL和/或使用CriteriaQuery)?我发现所有这些其他类似的问题,但没有人帮助我,因为他们都依赖于从 Project
到 Person
(它不存在从 Person
):
我不想在'Person'中插入一个属性只是为了查询,因为它在我的模型中没有意义。
感谢!!
加入project.resources人员
其中person.id =:personId
如果您确实需要它,我会让您将其转换为标准,但我不会使用Criteria为这样的基本静态查询提供任何优势。
Similar to this post, I have these (almost the same) classes:
public class Project {
@ManyToMany
private Set<Person> resources;
// get and set of resources
}
public class Person {
}
The difference is that my properties are private (using beans as entities).
The question is: how would I create a query to return all projects of a determined person (in JPQL and/or using CriteriaQuery)?
I found all these other similar questions, but none helped me, because all of them rely on the navigation from Project
to Person
(which doesn't exist querying from Person
):
- JPQL ManyToMany select
- @ManyToMany JPA 2 complex query
- JPA 2.0 CriteriaQuery on tables in @ManyToMany relationship
I wouldn't like to insert a property inside 'Person' just to be able to make the query, because it doesn't make sense in my model.
Thanks!!
select project from Project project
join project.resources person
where person.id = :personId
I'll let you translate this to criteria if you really want it, but I don't hink using Criteria for such a basic static query offers any advantage.
这篇关于JPA查询与@ManyToMany关系,没有导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!