严重: Exception occurred during processing request: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1
org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1
这个错误是因为使用时 自己定义了一个方法:
public List<T> getResult(String hql, Object[] parameters) {
// TODO Auto-generated method stub
Query query=sessionFactory.getCurrentSession().createQuery(hql);
//注入?
if(parameters!=null&¶meters.length>0){
for(int i=0;i<parameters.length;i++){
query.setParameter(i, parameters[i]);
}
}
return query.list();
}
调用改方法时:
String hql = "from Blogtype where belongId is null";
return getResult(hql, new Object[]{i});
导致?和传入的值数量不一致引起错误