日期:2014-05-18  浏览次数:20741 次

新手使用find()问题求助。
我的代码:

import   java.util.List;

import   org.acegisecurity.providers.encoding.Md5PasswordEncoder;
import   org.acegisecurity.providers.encoding.PasswordEncoder;
import   org.apache.commons.logging.Log;
import   org.apache.commons.logging.LogFactory;
import   org.springside.core.dao.HibernateEntityDao;

import   com.my.security.model.User;


public   class   CustomerUser   extends   HibernateEntityDao <User> {
  final   Log   buzzLog   =   LogFactory.getLog(Constants.BUSINESS_LOG);


public   int   UserCheck(String   userid,   String   passwd){
    buzzLog.info( "---   Check   Begin   --- ");
    int   ret   =   1;
    String   hql;
    String   passwd2;
    PasswordEncoder   passwordEncoder   =   new   Md5PasswordEncoder();
    passwd2   =   passwordEncoder.encodePassword(passwd,   null);
    hql   =   "from   user   u   where   number=?   and   passwd=? ";
    try   {
      buzzLog.info( "---find   begin   ---\n "   +   hql);
      List   userList   =   find(hql,userid,passwd2);
      if   (   userList.size()   >   0)   {
        ret   =   0;
        }
    }
    catch(Exception   e){
      buzzLog.info( "---find   error   --- ");
      e.printStackTrace();
      ret   =   -1;
    }
    return   ret;
  }
public   List   find(String   hql,   Object...   values)   {
Assert.hasText(hql);
return   getHibernateTemplate().find(hql,   values);
}
}
 

执行时报错:

2007-07-09   13:05:26,375   INFO   [business]   -   <---   Check   Begin   --->
2007-07-09   13:05:26,421   INFO   [business]   -   <---find   begin   ---
from   ss_users   u   where   number=?   and   passwd=?>
2007-07-09   13:05:26,421   INFO   [business]   -   <---find   error   --->
java.lang.NullPointerException

  at   org.springside.core.dao.HibernateGenericDao.find(HibernateGenericDao.java:159)
  at   com.my.commons.CustomerUser.UserCheck(CustomerUser.java:34)   <就是List   userList   =   find(hql,userid,passwd2);>
  at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native   Method)
  at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at   java.lang.reflect.Method.invoke(Method.java:585)
  at   org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
  at   org.apache.struts.actions.DispatchAction.execute(DispatchAction.j