问题
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