sdawar 2 Posted October 3, 2011 Report Share Posted October 3, 2011 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!! 1 Quote Link to post Share on other sites
Ingolme 1,032 Posted October 3, 2011 Report Share Posted October 3, 2011 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. Quote Link to post Share on other sites
trevelluk 0 Posted October 3, 2011 Report Share Posted October 3, 2011 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.