0

I have a query

select ... from x join y on ..
where ... and :age between y.min and y.max

But when executing the query with hibernate i receive

org.hibernate.QueryParameterException: could not locate named parameter [age]

What is wrong?

2
  • 2
    Can you post the actual query? Commented May 21, 2012 at 9:46
  • The full query as well, along with the annotation you're using Commented May 21, 2012 at 9:49

2 Answers 2

2

Since you haven't posted the actual query, my inference from your snippet is that you have the :age parameter in the wrong place in the query. The syntax for a query's where clause is column_name operator value so what you should have in place of :age is the actual column name of one of your tables. What you are probably trying to do is y.min >= :age and y.max <=:age.

Sign up to request clarification or add additional context in comments.

5 Comments

age is not a parameter. And the query works well when i put age (12 for example) manually, not as named parameter.
Do you know that where 1=1 is valid in sql? And if age is not a parameter, why does it have a : in front?
Ah okey. Now i understand. It's not by chance named "named parameter". So :value should be value of some parameter. Right?
so the solution is y.min >= :age and y.max <=age ?
close. y.min >= :age and y.max <=:age would probably do the trick.
0

check your java code if you have passed "age" properly. Possibly you might have missed it, or maybe misspelled it.

It will be good if you share you java side code also.

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.