在 JPQL 中,如何访问命名参数的属性?

发布于 2024-11-18 13:28:36 字数 408 浏览 1 评论 0原文

我正在使用 Hibernate 3.5.4-Final。

我想将一个实体作为命名查询的参数传递,然后访问该查询中该命名参数的持久属性。我想这样做:

@NamedQuery(name = "hello", query = "SELECT p FROM WorkPackage p WHERE p IN (:workPackage).relatedWorkflows")

问题是在查询接近结束时,

(:workPackage).relatedWorkflows

导致 Hibernate 抛出部署时 QuerySyntaxException。删除括号没有帮助;为了清楚起见,我把它们留在了里面。有什么办法可以解决这个问题,还是我必须以编程方式执行此操作?

I'm using Hibernate 3.5.4-Final.

I want to pass an entity as a parameter of a named query, and then access a persisted property of that named parameter in that query. I want to do this:

@NamedQuery(name = "hello", query = "SELECT p FROM WorkPackage p WHERE p IN (:workPackage).relatedWorkflows")

The problem is near the end of the query, in the

(:workPackage).relatedWorkflows

which causes Hibernate to throw a deploy-time QuerySyntaxException. Remove the parentheses doesn't help; I left them in for clarity. Is there any way around this, or am I going to have to do this programmatically?

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

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

发布评论

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

评论(1

国产ˉ祖宗 2024-11-25 13:28:36

你不能。您必须将属性值本身传递给查询:

@NamedQuery(name = "hello", query = "SELECT p FROM WorkPackage p WHERE p IN (:relatedWorkflows)")

query.setParameterList("relatedWorkflows", workPackage.getRelatedWorkflows());

You can't. You have to pass the property value itself to the query:

@NamedQuery(name = "hello", query = "SELECT p FROM WorkPackage p WHERE p IN (:relatedWorkflows)")

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