开发者

In JPQL, how do you access properties of named parameters?

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 th开发者_高级运维is programmatically?


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());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜