-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: java.lang.NullPointerException
PostPosted: Fri Sep 07, 2007 9:51 am 
Newbie

Joined: Wed Sep 28, 2005 8:46 am
Posts: 9
I have a Struts and Hibernate based application. After uploading application on the server, when I login I get "HTTP Status 500 - Internal Server Error". The Exception is "javax.servlet.ServletException" and the root cause of the exception is: "java.lang.NullPointerException" at line:

tx = session.beginTransaction();

Here are few lines of code:
Code:
Transaction tx = null;
      try {
         String queryString =" select u from User as u where  u.userName='"+username+"' and u.password='"+password+"' ";
         session = HibernateSessionFactory.currentSession();


// the line where I get the NullPointerException
         tx = session.beginTransaction();
         Query query = session.createQuery(queryString);
...........
...........

Code:
public static Session currentSession() throws HibernateException {
      Session session = (Session) threadLocal.get();
      ResourceBundle resourceBndl = ResourceBundle.getBundle("resources.ApplicationResources", Locale.getDefault());
      try {
         if (session != null && !session.isOpen())
            session = null;
         if (session == null) {
            if (sessionFactory == null) {
               //sessionFactory = new Configuration().configure().buildSessionFactory();
                  sessionFactory = new Configuration().configure(new File(resourceBndl.getString("hibernate.config"))).buildSessionFactory();
            }
            session = sessionFactory.openSession();
            threadLocal.set(session);
         }
      } catch (Exception e){
         System.err.println("Error Creating SessionFactory");
         e.printStackTrace();
      }

      return session;
   }


resourceBndl.getString("hibernate.config"); is the path where "hibernate.cfg.xml" file is located. I got the above exception on MY COMPUTER only when path for "hibernate.cfg.xml" file was not correct. After correcting the path everything was OK. I have also corrected the path on the server (now it is server path, NOT MY COMPUTER's path), but I am still getting the same problem even after restarting the Tomcat.

Can someone please help me to solve this issue. Its very urgent.

Thanks.

Joseph Bashir


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 2:29 pm 
Newbie

Joined: Fri Sep 07, 2007 4:16 am
Posts: 16
Why don't u use direcly SessionFactory.openSession()?


Rate me


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.