HIbernate struts2会话空指针异常

时间:2015-09-14 17:07:16

标签: hibernate struts2 struts2-s2hibernate

我正在使用struts2和hibernate创建一个简单的登录示例。为此,我使用@SessionTarget注释创建一个会话变量。但是,当我尝试使用此会话变量时,我得到空指针异常。

            @SessionTarget
            Session session;

            public void userLogin(String userName, String password) {
                  try {
                  String hql = "select user_privilege from user_details log where log.userName=:userName and log.password=:passw";
                  Query query = session.createQuery(hql); // From here I am getting exception
                  query.setParameter("userName", userName);
                  query.setParameter("password", passw);
                  List result = query.list();
                  Iterator iterator = result.iterator();
                  while(iterator.hasNext()){
                    userId = (int) iterator.next();
                  }
                } catch (HibernateException e) {
                } finally {
                  //session.close();
                }                   
            }

0 个答案:

没有答案