是否可以在选定的集合上调用 elements(?) ?
我有两个实体,它们具有多对多关系。例如 AEnt 和 BEnt:
class AEnt {
//....
String name;
Set<BEnt> bs;
}
class BEnt {
//....
}
我想选择这样的 BEnt,其 AEnt 的名称类似于“somthing”。我现在的查询是这样的:
from BEnt b where b in
(select elements(a.bs) from AEnt a where a.name like :name)
但问题是 Hibernate 首先调用所有 AEnts-BEnts 上的元素,实际上忽略了我的“like”过滤器。因为我有数百万个 AEnt-BEnt 关系,所以查询变得没有响应。有没有办法只调用选定的 AEnt 集合上的元素?或者更好的查询?
谢谢。
I have two entities which they have a many-to-many relationship. E.g. AEnt and BEnt:
class AEnt {
//....
String name;
Set<BEnt> bs;
}
class BEnt {
//....
}
I want to select such BEnts where the names of their AEnts are like "somthing". My query now is like this:
from BEnt b where b in
(select elements(a.bs) from AEnt a where a.name like :name)
But the problem is Hibernate at first calls elements on all AEnts-BEnts and in fact ignores my "like" filter. Because I have millions of AEnt-BEnt relations, the query becomes not responding. Is there a way to call elements just on the selected set of AEnts? Or a better query?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您在
BEnt
中引用了AEnt
- 即多对一,因为您在AEnt
之间有一对一的关系代码>和<代码>BEnt。试试这个:I assume you have a reference to
AEnt
inBEnt
- ie a many-to-one, given you have a one-to-mant relationship betweenAEnt
andBEnt
. Try this: