0

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();
                }                   
            }
Roman C
  • 49,761
  • 33
  • 66
  • 176
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94
  • 4
    possible duplicate of [Struts + Hibernate: @SessionTarget not working](http://stackoverflow.com/questions/22549634/struts-hibernate-sessiontarget-not-working) – Roman C Sep 14 '15 at 17:12
  • Thank you. It solved my problem. Can you please suggest me what is best way to declare session object in hibernate? – Shiladittya Chakraborty Sep 14 '15 at 17:41
  • Using this plugin you just declare it with annotation, you don't need to delve into the details of hibernate session creation and maintenance. – Roman C Sep 14 '15 at 18:01

0 Answers0