Jump to content

Null Pointer Exception At Sesionfactory.getcurrentsession


Recommended Posts

Hi,I have to add a new class in my project in which I have to query the database using hibernate.

  private SessionFactory sessionFactory;     public boolean validatePlanTerminated(String productPlanKey)	 {		                    StringBuffer hqlQuery = new StringBuffer("SELECT ");           hqlQuery.append("count(pr_criteria.criteria_key) as COUNT from pr_criteria,pr_plan_criteria " );           hqlQuery.append(" where plan_key = '"+productPlanKey+"' and pr_criteria.criteria_key=pr_plan_criteria.criteria_key ");           hqlQuery.append(" and pr_criteria.end_date is not null");           Session session = sessionFactory.getCurrentSession();        //sessionFactory = new Configuration().configure().buildSessionFactory();               int count = Integer.parseInt((session.createSQLQuery(hqlQuery.toString()).uniqueResult()).toString());        if (count > 0)		 {			 return true;		 }		  return false;		    	 }

I am getting a null pointer exception at this lineSession session = sessionFactory.getCurrentSession();Please help!!

  • Like 1
Link to post
Share on other sites

It sounds to me like it getCurrentSession() is returning a null pointer. You might want to look at your getCurrentSession() method to see what is causing the null pointer to be returned. If sessionFactory isn't your own class, then you'll have to check the documentation.

Link to post
Share on other sites
Session session = sessionFactory.getCurrentSession();//sessionFactory = new Configuration().configure().buildSessionFactory();
This looks a bit unusual here, as it looks to me as though the second line (if it wasn't commented out) would be the one initialising sessionFactory.I would have thought you'd need something like:
sessionFactory = new Configuration().configure().buildSessionFactory();Session session = sessionFactory.getCurrentSession();

Otherwise there's nothing to initialise sessionFactory, and so it will be a null pointer.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...