当前位置: 代码迷 >> Java Web开发 >> nested   exception   is   org.hibernate.QueryException:
  详细解决方案

nested   exception   is   org.hibernate.QueryException:

热度:405   发布时间:2016-04-17 15:04:35.0
大家看看这个哪里错误了
AsminuserDAO中的一个方法
public   List   findByStr(String   queryString,   Map   paramMap)   {
//   TODO   自动生成方法存根
  log.debug( "finding   Adminuser   by   String   sql:   ");
                try   {
                     
      return   getHibernateTemplate().find(queryString,   paramMap);//是不是这句有问题
                }   catch   (RuntimeException   re)   {
                      log.error( "find   by   property   name   failed ",   re);
                      throw   re;
                }


}


被另一个程序调用
public   class   ServiceImp   implements   IService   {
private   AdminuserDAO   adminuserDAO;
public     AdminuserDAO   getAdminuserDAO(){
return   adminuserDAO;
}
public   void   setAdminuserDAO(AdminuserDAO   adminuserDAO){
this.adminuserDAO=adminuserDAO;
}
//private   static   String   hql   = "from   vo.Adminuser   u   where   u.UserName=? ";

public   boolean   isAdmin(String   username,   String   password)   {


String   queryString= "from   Adminuser   as   model   where     model.userName=?   and   password=? ";
Map   paramMap   =   new   HashMap();

paramMap.put( "userName ",   username);
paramMap.put( "password ",   password);
                  List   AdminList=adminuserDAO.findByStr(queryString,   paramMap);
if   (AdminList.size()> 0)   {

return   true;

}

return   false;

}

}

错误信息是
javax.servlet.ServletException:   Expected   positional   parameter   count:   2,   actual   parameters:   [{userName=maxin,   password=maxin}]   [from   Adminuser   as   model   where   model.userName=?   and   password=?];   nested   exception   is   org.hibernate.QueryException:   Expected   positional   parameter   count:   2,   actual   parameters:   [{userName=maxin,   password=maxin}]   [from   Adminuser   as   model   where   model.userName=?   and   password=?]
大家多多指教谢谢

------解决方案--------------------
Map paramMap = new HashMap();
别用这个

用Object[] ob = new Object[]{username, password};

最好的还是封装到一个FROMBEAN里或者POJO类里
  相关解决方案