Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 this programmatically?

like image 652
Nick Avatar asked Jul 06 '11 19:07

Nick


1 Answers

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());
like image 194
JB Nizet Avatar answered Oct 27 '22 11:10

JB Nizet