在 JPA 中加入命名查询

发布于 2024-09-28 02:46:13 字数 132 浏览 0 评论 0原文

我想知道是否可以在 JPA 中加入 2 个命名查询。作为示例,我有两个以下命名查询

1 - 获取所有活动用户
2 - 获取给定公司的所有用户

我是否可以加入上面两个命名查询并获取 获取给定公司的所有活跃用户。

I want to know whether I can join 2 named queries in JPA. As an example I have two following named queries

1 - Get all the active users
2 - get all the users for a given company

Is it possible for me to join above two named queries and get
get all the active users for a given company.

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

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

发布评论

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

评论(2

友欢 2024-10-05 02:46:13

不要为此使用 NamedQuery。直接将查询字符串传递给该方法是最好的选择。

您必须了解 createNamedQuery(String name) 方法采用命名查询的名称。而 createNamedQuery(String qlString) 接受查询字符串,因此这符合您的需求。

或者

为此目的创建一个单独的 NamedQuery

Don't use NamedQuery for this. Directly passing a query string to the method is your best bet.

You must understand that the method createNamedQuery(String name) takes name of a named query. Whereas, createNamedQuery(String qlString)takes a query string, so this fits your need.

Or

Create a separate NamedQuery for this very purpose.

诗酒趁年少 2024-10-05 02:46:13

我是否可以加入上述两个命名查询并获取给定公司的所有活跃用户

不,那不可能。要么编写一个智能命名查询,它可以使用参数来表达所有情况(如果可能),要么使用多个命名查询。

如果您使用 JPA 2.0,Criteria API 可能是编写动态查询的另一个(更好)选项。

Is it possible for me to join above two named queries and get all the active users for a given company.

No, that's not possible. Either write a smart named query that can take parameters to express all cases (if possible) or use several named queries.

And if you are using JPA 2.0, the Criteria API might be another (better) option to write dynamic queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文