JDO例外:“查询需要1个参数,但是已经提供了2个值”。 [英] JDO Exception: "Query requires 1 parameters, yet 2 values have been provided."
问题描述
declareParameters
语句,但下方的代码会产生一个错误,声称只接受一个参数: 查询需要1个参数,但已提供2个值。
是 amountP
和 taxP
:
javax.jdo.Query query = pm.newQuery(Main.class);
query.setFilter(amount == amountP&&& tax< taxP);
query.declareParameters(int amountP);
query.declareParameters(int taxP);
列表< Main> results =(List< Main>)query.execute(amountP,taxP);
然而,通过以下更改,它可以正常工作。
javax.jdo.Query query = pm.newQuery(Main.class);
query.setFilter(amount == amountP&&& tax< taxP);
query.declareParameters(int amountP,int taxP);
列表< Main> results =(List< Main>)query.execute(amountP,taxP);
我的问题是:原始语法有什么问题?
更新:这个问题已被其他人报告过,但没有解释。 JDO API 似乎要求所有参数一次性设置。该方法被称为 declareParameters
,它似乎是一个setter,而不是加法器。该方法的名称可能会引起误解,文档并不是那么好,但它看起来就是这样。
这与扩展不同支持setter和adder: addExtension()
, setExtensions()
。
Despite the fact that my JDO query contains TWO declareParameters
statements, the code below produces an error claiming only one parameter is accepted:
Query requires 1 parameters, yet 2 values have been provided.
The two parameters are amountP
and taxP
:
javax.jdo.Query query= pm.newQuery(Main.class);
query.setFilter("amount == amountP && tax < taxP");
query.declareParameters("int amountP");
query.declareParameters("int taxP");
List<Main> results = (List<Main>)query.execute (amountP, taxP);
However, with the following changes, it works.
javax.jdo.Query query= pm.newQuery(Main.class);
query.setFilter("amount == amountP && tax < taxP");
query.declareParameters("int amountP, int taxP");
List<Main> results = (List<Main>)query.execute (amountP, taxP);
My question is: What was wrong with the original syntax?
Update: This problem has been reported by others but without explanation.
The JDO API seems to require that all parameters are set at once. The method is called declareParameters
, which seems to be a "setter", and not an "adder". The method name may be misleading, and the documentation is not that great, but it seems to be just the way it is.
This is different from "extensions" that both supports a setter and an adder: addExtension()
, setExtensions()
.
这篇关于JDO例外:“查询需要1个参数,但是已经提供了2个值”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!