-->
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.  [ 4 posts ] 
Author Message
 Post subject: Trying to get Hibernate to work
PostPosted: Thu Nov 17, 2005 11:58 am 
Newbie

Joined: Thu Nov 17, 2005 11:51 am
Posts: 1
Hi

I am trying to create a session with Hibernate but get a Nullpointerexception all the time. I'm using Eclipse and all of my jar files in order but I still can't create the session! I've been lurking around the web and have noticed that nobody ever creates a session in a JSP, all of the examples I've found are used in servlets - is that the problem? thx

Hibernate version:
3.0.5


Code between sessionFactory.openSession() and session.close():
<%
Session hSession = HibernateSessionFactory.currentSession();
hSession.close();
%>


Full stack trace of any exception that occurs:
exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.NullPointerException
tn20.dataaccess.persistence.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:62)
org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:54)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Name and version of the database you are using:
Sql 5


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
HibernateSessionFactory is not a class packaged with Hibernate. Please follow the Getting Started guide here: http://www.hibernate.org/ForumMailingli ... AskForHelp

There is no difference between the code needed to start Hibernate in a Servlet, in a main() method, or in a JSP.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 3:25 pm 
Newbie

Joined: Fri Oct 28, 2005 10:54 pm
Posts: 12
The samples of code that I've been able to run have used SessionFactory, not HibernateSessionFactory.

For example (my code uses Hibernate 2 and there's a slight difference for H3)

Configuration config = new Configuration();
SessionFactory sessionFactory = config.buildSessionFactory();
...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 5:40 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Configuration config = new Configuration();
SessionFactory sessionFactory = config.buildSessionFactory();

this is same for h2 and h3

use eclipse, download wtp and debug NPE


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.