7

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 two parameters in one Query?

2 Answers 2

10

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();
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.