-->
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.  [ 7 posts ] 
Author Message
 Post subject: Null Pointer Exception
PostPosted: Mon Sep 01, 2003 3:00 pm 
Newbie

Joined: Mon Sep 01, 2003 2:49 pm
Posts: 8
Hello,
what is my mistake? I have opened the session with my own connection.(session = _sessions.openSession(con);) The connection is alredy testet.

But it throws a null pointer exception...

How can i close the session. Should i close my connection first, or after the session?

I used this code in a Sevlet witch is inherited from HTTPServlet. Could that be a problem?

Thanks in advance for some hints..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 4:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
What is the stack trace for the NPE?


Top
 Profile  
 
 Post subject: Re: Stack trace for npe
PostPosted: Tue Sep 02, 2003 2:35 am 
Newbie

Joined: Mon Sep 01, 2003 2:49 pm
Posts: 8
Hy steve,
I hope this informations will help to get my fault...


By running this code:

**************************************************************************

private void initStartParameters(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, HibernateException {

Navigation nav= new Navigation();
nav.setId_node(300);
nav.setId_parent(1);
nav.setName("Test Roger...");
nav.setOrder(1);


Session session= null;
Transaction tx = null;
Connection con=null;
try {
System.out.println("Test: try to connect...");
con=this.getConnection();
System.out.println("Test: connection set "+con);
session = _sessions.openSession(con);
System.out.println("Test open session with connection");
tx = session.beginTransaction();
System.out.println("Test begin to transact");
session.save(nav);
System.out.println("Test save new nav");
tx.commit();
System.out.println("Commit");
}
catch (HibernateException he) {
if (tx!=null) tx.rollback();
System.out.println(he);

}
catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
finally {
try {
//session.close();
con.close();


} catch (SQLException e1) {
System.out.println(e1);
e1.printStackTrace();
}
}

}

**************************************************************************


The server prints:

**************************************************************************
[02.09.03 08:26:52:759 CEST] 45f68a76 SystemOut O Test: try to connect...
[02.09.03 08:26:53:149 CEST] 45f68a76 SystemOut O Test: connection set
DB2Connection
{
connectionHandle = 1
SPConnected = false
source = erm
user = rmi
conArgs =
closed = false
describeCached = false
describeParam = true
isReadOnly = false
autoClose = false
LONGDATA compat = false
}

[02.09.03 08:26:53:165 CEST] 45f68a76 SystemOut O java.lang.NullPointerException
[02.09.03 08:26:53:181 CEST] 45f68a76 SystemErr R java.lang.NullPointerException
[02.09.03 08:26:53:181 CEST] 45f68a76 SystemErr R at com.clavisNET.erm.general.NavControllerHibernate2.initStartParameters(NavControllerHibernate2.java:201)
[02.09.03 08:26:53:181 CEST] 45f68a76 SystemErr R at com.clavisNET.erm.general.NavControllerHibernate2.doPost(NavControllerHibernate2.java:99)
[02.09.03 08:26:53:181 CEST] 45f68a76 SystemErr R at com.clavisNET.erm.general.NavControllerHibernate2.doGet(NavControllerHibernate2.java:162)
[02.09.03 08:26:53:181 CEST] 45f68a76 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
[02.09.03 08:26:53:181 CEST] 45f68a76 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[02.09.03 08:26:53:181 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[02.09.03 08:26:53:181 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
[02.09.03 08:26:53:196 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
[02.09.03 08:26:53:212 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
[02.09.03 08:26:53:212 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
[02.09.03 08:26:53:212 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
[02.09.03 08:26:53:212 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
[02.09.03 08:26:53:212 CEST] 45f68a76 SystemErr R at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
[02.09.03 08:26:53:212 CEST] 45f68a76 SystemErr R at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
[02.09.03 08:26:53:212 CEST] 45f68a76 SystemErr R at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:435)
[02.09.03 08:26:53:212 CEST] 45f68a76 SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
**************************************************************************

Thanks for your effort


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 2:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Looks to me like the _sessions instvar is null. I suggest you try stepping through code to see if the session factory is really there.


Top
 Profile  
 
 Post subject: Sorry...
PostPosted: Tue Sep 02, 2003 4:07 am 
Newbie

Joined: Mon Sep 01, 2003 2:49 pm
Posts: 8
Sorry for this stupid fault, but that can happend when i'm testing and trying. But i have now already some new problems...

I now its realy bad, but if i have my first example, everything will be better.

The exception occured by calling buildsessionFactory.

By calling this fubnctions:
******************************************************************************************
public void configure() throws HibernateException {
Configuration cfg=new Configuration().addClass(Navigation.class);
_sessions = cfg.buildSessionFactory();
System.out.println("Session factory: "+_sessions);
}

public void exportTables() throws HibernateException {
Configuration cfg = new Configuration().addClass(Navigation.class);
new SchemaExport(cfg).create(true, true);
}

******************************************************************************

The Server prints:

*****************************************************************************
[02.09.03 09:47:22:197 CEST] 7817d261 WebGroup I SRVE0180I: [ERM] [/ERM] [Servlet.LOG]: NavControllerHibernate2: init
[02.09.03 09:47:22:306 CEST] 7817d261 WebGroup E SRVE0026E: [Servlet-Fehler]-[org/dom4j/Attribute]: java.lang.NoClassDefFoundError: org/dom4j/Attribute
at com.clavisNET.erm.general.NavControllerHibernate2.configure(NavControllerHibernate2.java:71)
at com.clavisNET.erm.general.NavControllerHibernate2.doPost(NavControllerHibernate2.java:90)
at com.clavisNET.erm.general.NavControllerHibernate2.doGet(NavControllerHibernate2.java:170)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:435)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)

*****************************************************************************

Thanks, i realy hope after this problem every thing is ok and i don't bother you again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 4:09 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I recommend you read and work step by step with the "Hibernate Tomcat Quickstart Tutorial", from HibernateExamples.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 4:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
you must have dom4j.jar in your classpath


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