开发者

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

开发者 https://www.devze.com 2023-03-18 06:54 出处:网络
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:

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

精彩评论

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

关注公众号