[英]could not bind value to parameter
I'm running a query in Java using HQL and creating a parameter that looks like this: query.setParameter("month", month);
我正在使用HQL在Java中运行查询,并创建一个如下所示的参数:
query.setParameter("month", month);
The month variable is a BigDecimal that is between 1 and 12. However, the month variable was passed to the function running this query as an Object. month变量是一个介于1到12之间的BigDecimal。但是,month变量已作为对象传递给运行此查询的函数。 So when it is being set as a parameter it is seen as an Object.
因此,当将其设置为参数时,它将被视为对象。
When I run the query I get this error: 当我运行查询时,出现以下错误:
15:46:48,878 INFO [IntegerType] could not bind value '4' to parameter: 1; java.math.BigDecimal
15:46:48,878 ERROR [STDERR] java.lang.ClassCastException: java.math.BigDecimal
15:46:48,878 ERROR [STDERR] at org.hibernate.type.IntegerType.set(IntegerType.java:41)
15:46:48,878 ERROR [STDERR] at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
15:46:48,879 ERROR [STDERR] at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
15:46:48,879 ERROR [STDERR] at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:38)
The '4' is the value stored in my month variable. “ 4”是存储在我的month变量中的值。 So it's obviously something wrong with that parameter.
因此,该参数显然有问题。 What could possibly be causing this?
可能是什么原因造成的?
I fixed it. 我修好了它。 It was just a problem trying to add a BigDecimal to a constant number within the query.
尝试将BigDecimal添加到查询中的常数只是一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.