EclipseLink INTERSECT 过滤掉两个集合是否有共同元素

发布于 2025-01-21 02:04:09 字数 185 浏览 2 评论 0原文

有人可以帮忙吗?

实体A具有一组枚举的字段。

方法采用一组枚举。

任务 - 如果A.Field具有与传递的枚举集共有1个或更多元素,则过滤掉值。 我试图通过Intersect实现它,但结果尚未实现。

工作解决方案 - 不是成员,但只能用于1个参数...可以使用()实现,但我相信这不是一个好练习...

could anybody help?

Entity A has a field with set of enums.

Method takes a set of enums.

Task - filter out values if A.field has 1 or more elements in common with passed set of enums.
I was trying to achieve it via INTERSECT, but the result wasn't achieved.

Working solution - NOT MEMBER OF, but it could be used only for 1 parameter... possible to implement with for(), but I am sure that it isn't a good practice...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椒妓 2025-01-28 02:04:09

没有直接的方法可以将一个集合与JPA中的另一个集合进行比较。

围绕该问题的解决方案虽然涉及次数,但JPA将采取什么措施评估您的条款成员。一个子查询使您可以查看集合中的单个值并将其与另一个值进行比较,并将其使用导致您的主要查询。按照:

"Select a from A a where a.id not in (select distinct aPrime.id from A aPrime join aPrime.field field where field in :parameterList)"

我不是DBA,但是如果有人抱怨这是效率低下的,那么还有许多其他表达方式,可能存在:

"Select a from A a where exists (select aPrime from A aPrime join aPrime.field field where field in :parameterList and aPrime.id = a.id)"

There is no direct way to compare one collection to another in JPA.

Solutions around the issue though involve subqueries, very similar what JPA will do to evaluate your MEMBER OF clause. A sub-query lets you look at individual values in a collection and compare it to the other, and use that result in your main query. Something along the lines of:

"Select a from A a where a.id not in (select distinct aPrime.id from A aPrime join aPrime.field field where field in :parameterList)"

I'm not a DBA, but if one complains this is inefficient, there many other ways of being expressed, possibly with exists:

"Select a from A a where exists (select aPrime from A aPrime join aPrime.field field where field in :parameterList and aPrime.id = a.id)"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文