ssh项目getHibernateTemplate().find()出现空指针异常

public Employee findByUsernameAndPassword(Employee employee) {
        String hql = "from Employee where username = ? and password = ?";
        List<Employee> list = this.getHibernateTemplate().find(hql,employee.getUsername(),employee.getPassword());
        if(list.size()>0) {
            return list.get(0);
        }
        return null;
    }

异常:

2017-09-26 11:03:49 [信息] Exception occurred during processing request: null
java.lang.NullPointerException
    at cc.test.employee.dao.impl.EmployeeDaoImpl.findByUsernameAndPassword(EmployeeDaoImpl.java:18)
阅读 4k
5 个回答

行号?
到底employeenull还是list

打印下getHibernateTemplate吧

employee是否为null?

新手上路,请多包涵

HibernateTemplate 有注入sessionfactory么?

调用this.getHibernateTemplate() 报空指针异常了或者 employee 为null了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题