简体   繁体   中英

strange exception on named parameter for native query in hibernate

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?

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM