一个关于this.getHibernateTemplate()空指针异常的问题
DALUser.java:public Users login(String name,String pwd) {
String sql = "from Users p where p.name=? and p.password=?";
List list = this.getHibernateTemplate().find(sql, new String []{name,pwd});
if(list.size()>0){
return (Users)list.get(0);
}
return null;
}这里没有问题、能够查询到数据、但是在
DALProduct.java:
public List findProductsByUserID(int id) {
String sql="from Products p where p.UserID=?";
//this.getHibernateTemplate();
List list=new ArrayList();
//Users users=(Users)ActionContext.getContext().getSession().get("login_user");
//System.out.println(users.getAddress());
list = this.getHibernateTemplate().find(sql,id);
//Products products=(Products)list.get(0);
return list;
}中却出现了空指针异常。而且用这里的sql语句在数据库中能查到数据!已经确定this.getHibernateTemplate()的值为空了 这个问题该怎么解决啊? --------------------编程问答--------------------
我也遇到了,暂时没办法,关注!!! --------------------编程问答-------------------- public List<login_user>(实体类) findProductsByUserID(int id) {
String hql="from Products p where p.UserID=?";
List<login_user> list=super.getHibernateTemplate().find(hql,id);
return list.size()>0&&list!=null? list.get(0):null;
} --------------------编程问答-------------------- String hql="from Products p where p.loginUser.userID=?";
product和login_user实体类应该是多对多关系,通过product中的loginUser对象.userID,去获取login_user表中的id所对应的信息
上面看错了 --------------------编程问答-------------------- 首先确定都有setter?
补充:Java , Java EE