当您调用第三方库并遇到此类错误时,您总是想知道您是否没有正确使用 API。在您的情况下,很容易从 JavaDoc 中看出正确的方法是setParameterList
而不是setParameter
. 请记住,JavaDoc 是您的圣经。
我正在为类 Query 复制粘贴 Hibernate 3.3 Javadoc:
Query setParameter(int position, Object val)
Bind a value to a JDBC-style query parameter.
Query setParameter(int position, Object val, Type type)
Bind a value to a JDBC-style query parameter.
Query setParameter(String name, Object val)
Bind a value to a named query parameter.
Query setParameter(String name, Object val, Type type)
Bind a value to a named query parameter.
Query setParameterList(String name, Collection vals)
Bind multiple values to a named query parameter.
Query setParameterList(String name, Collection vals, Type type)
Bind multiple values to a named query parameter.
Query setParameterList(String name, Object[] vals)
Bind multiple values to a named query parameter.
Query setParameterList(String name, Object[] vals, Type type)
Bind multiple values to a named query parameter.
Query setParameters(Object[] values, Type[] types)
Bind values and types to positional parameters.