HIbernate struts2 session null pointer exception

ⅰ亾dé卋堺 提交于 2020-01-07 09:05:55

问题


I am creating one simple login example using struts2 and hibernate. For doing this I am creating one session variable with @SessionTarget annotation. But when I am trying to use this session variable then I am getting null pointer exception.

            @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();
                }                   
            }

来源:https://stackoverflow.com/questions/32570173/hibernate-struts2-session-null-pointer-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!