Jump to content

Null Pointer Exception At Sesionfactory.getcurrentsession


sdawar

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!!

Link to comment
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 comment
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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...