JPA Criteria API:如何选择嵌套集合中的属性
我有一个类 Customer
和 CustomerDependant
实体。 客户
与其依赖者具有多对多的双向关系。我需要找到按姓名和附属姓名过滤的客户。
它在 JPQL 中做了类似的事情:
select c join fetch c.dependants d from Customer c where c.name like
'foo' and d.name like 'foo'
How I can do the same thing with JPA Criteria Queries?
I have a class Customer
and CustomerDependant
entities. Customer
has many to many bi-directional relationship with its dependents. I need to find customers filtering by name and dependent name.
It's done something like this in JPQL:
select c join fetch c.dependants d from Customer c where c.name like
'foo' and d.name like 'foo'
How I can do the same thing with JPA Criteria Queries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
摘自 JPA 规范第 6.5.4 节
此查询等效于以下 Java 持久性查询语言查询:
这是我在没有 fetch 的情况下执行的操作
Fetch 是一种连接类型,所以我想您也可以尝试一下。
Taken from JPA Specification section 6.5.4
This query is equivalent to the following Java Persistence query language query:
This is what I do it without fetch
Fetch is a type of join, so I guess you could experiment with that too.