简体   繁体   English

hibernate中本机查询的命名参数奇怪的异常

[英]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 但是当我收到hibernate执行查询时

org.hibernate.QueryParameterException: could not locate named parameter [age] org.hibernate.QueryParameterException:找不到命名参数[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. 由于您尚未发布实际查询,因此我的摘录中的推断是您在查询中的错误位置使用:age参数。 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. 查询的where子句的语法是column_name operator value因此您应该具有:age内容:age是其中一个表的实际列名。 What you are probably trying to do is y.min >= :age and y.max <=:age . 您可能要做的是y.min >= :age and y.max <=:age

check your java code if you have passed "age" properly. 如果你已经正确地通过了“年龄”,请检查你的java代码。 Possibly you might have missed it, or maybe misspelled it. 可能你可能错过了它,或者拼错了它。

It will be good if you share you java side code also. 如果你也分享你的java边码也会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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