-->
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.  [ 13 posts ] 
Author Message
 Post subject: Problem with StatelessSession
PostPosted: Tue Jan 20, 2009 1:21 am 
Newbie

Joined: Mon Jan 19, 2009 9:20 am
Posts: 7
Location: India
I am using StatelessSession for update/insert large number of data ( more than 100000). In between I am getting Nullpointer exception.

My sample code.

Code:
Session session = sessionFactory.openStatelessSession();
Transaction tx = session.beginTransaction();
ScrollableResults itemCursor =
session.createQuery("from Item").scroll();
while ( itemCursor.next() ) {
   Item item = (Item) itemCursor.get(0);
   Detail details = new Details();
   session.insert(details);
   modifyItem(item);
   session.update(item);
   count++;
   if(count % 100  == 0)
   {
         tx.commit();
         tx = session.beginTransaction();
   }
}
tx.commit();
session.close();


Here I have found that error is in session.insert(details); line.
When I have print error trace it is simple one line
Code:
java.lang.NullPointerException


Here my Hibernate Version is 3.0
Oracle 10g

Please Help..

_________________
Kamlesh Koringa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 3:37 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
So what is the complete stacktrace?

It may not be related but... doesn't the call to 'tx.commit()' inside the 'if' statement destroy/closes the itemCursor? I think it would if the cursor lives on the server side but maybe not if the complete results already has been loaded by the client.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 3:49 am 
Newbie

Joined: Mon Jan 19, 2009 9:20 am
Posts: 7
Location: India
Thanks for reply

Here i have print stack trace. It is noly one line trace. no other information printed in log

Code:
java.lang.NullPointerException


I dont think tx.commit() will close/destroy itemCursor because it is perfactly working with normal session. and I have found error in session.insert(details);

Thanks

_________________
Kamlesh Koringa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 3:57 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
Here i have print stack trace. It is noly one line trace


This is not a stacktrace. A stacktrace will list the all classes/methods/line number that have been called to reach the code were the error happens. You can print the stacktrace by calling the Exception.printStackTrace() method.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 5:13 am 
Newbie

Joined: Mon Jan 19, 2009 9:20 am
Posts: 7
Location: India
Thanks for reply

My exception handling code is

Code:
try
{
      // Main code
}
catch (Exception e)
{
   logger.error("Exception in verify Orders ::",e);
   e.printStackTrace();
   session.getTransaction().rollback();
   throw e;
}


and i got out put log is

Code:
Exception in verify Orders :: java.lang.NullPointerException


It is strange but I am getting one line stacktrace.

_________________
Kamlesh Koringa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 5:54 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
e.printStackTrace() prints to stderr so you have to figure out where this ends up. I don't know which logging implementation you are using. Maybe it can be configured to print the entire stacktrace.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 6:03 am 
Newbie

Joined: Mon Jan 19, 2009 9:20 am
Posts: 7
Location: India
Thanks for your reply

But I have check stderr.log file in my tomcat and there is one line stacktrace which I have print.

Here I am using log4j and it is printing all stacktrace for other errors.
In this case it is printing one line trace.

Thanks

_________________
Kamlesh Koringa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 6:08 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Do you know, when exactly your error happens? For example after inserting 100 rows?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 6:23 am 
Newbie

Joined: Mon Jan 19, 2009 9:20 am
Posts: 7
Location: India
Hi
It is totally random and only happen when i am trying to process more than 100000 records. Same error generated after some time from process starts. In my last run error generated after 8512 record processed. I have checked that error is not generated on particular record.

This code is working fine for date when records are 185

Is this any bug of hibernate??

Thanks

_________________
Kamlesh Koringa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 7:05 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Hmmm.... Can this be some memory-related problem? Sometimes when you run out of memory there is not even enough room to create a stack trace and the output will end with a simple one-line error message. I have only seen this as a 'java.lang.OutOfMemoryError'. But maybe it can also take the form of a NullPointerException.

Have you tried to increase the memory? Or decrease it to see if it happens earlier.
You may also want to display some debugging info about the memory usage at regular intervals.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 7:52 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
hello friend
i think u may go with batch processing.

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 8:28 am 
Newbie

Joined: Mon Jan 19, 2009 9:20 am
Posts: 7
Location: India
HI
Yes I want to do batch processing. I have successfully run this code with normal session. Now I am trying with StatelessSession and wants to compare both performance.

Can any body tell me which way is good for my code.

Thanks

_________________
Kamlesh Koringa


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 1:36 am 
Newbie

Joined: Mon Jan 19, 2009 9:20 am
Posts: 7
Location: India
HI

I have run same code with websphere 6.0 and there is no error. So this error only occurs in Tomcat server.

Here my tomcat configuration.

Tomcat 4.1
JDK 1.4
Hibernate 3.0

Any one have idea why this is not working with TOMCAT.

I have also found that StatelessSession take more time than Normal session with batch processing.

Thanks

_________________
Kamlesh Koringa


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