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();
}
}
struts.xml
<package name="default" extends="hibernate-default">
<action name="fillvacancy" method="execute" class="com.templateproject.action.FillVacancyAction">
<result name="success">/vacancy/fillvacancy.jsp</result>
<result name="input">/vacancy/userhome.jsp</result>
</action>
</package>
I have already asked this question before. And found one answer from this link Struts + Hibernate: @SessionTarget not working.
But this solution not solved my problem.
How can I solve this issue?