There are two types of query parameters binding in the Hibernate Query. One is positioned parameter and another one is named parameter.
Can I use these t开发者_如何学Pythonwo parameters in one Query?
Sure you can, as long as you make sure all positional parameters precede any named parameters. Heres an example:
Query q =session.createQuery("select u from User u where u.location=? and u.id in (:user_ids)");
q.setParameter(0, location);
q.setParameterList("user_ids", userIds);
return q.list();
I Don't think so, if you try it, hibernate you give you the following error:
org.hibernate.hql.ast.QuerySyntaxException: cannot define positional parameter after any named parameters have been defined
Why would you want to do that?
Edit: Jeshurun offers a much better solution. Please check his answer below.
精彩评论