-->
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: Session closes while I am inserting data
PostPosted: Fri Mar 05, 2010 4:49 am 
Newbie

Joined: Sun Feb 14, 2010 7:13 pm
Posts: 6
Hi everybody,
I am facing a strange Hibernate behavior, I think due to session timeout.

I have to insert a lot of data into the database. The insertion works for the first entries, but a a certain point I get an org.hibernate.SessionException: Session is closed! exception.

My insert method works in the following way:
    I get a session from a sessionFactory I created following a tutorial found in the internet
    I create a transaction and I insert all the data using that transaction (This is the point where I get the exception)
    I commit the transaction when the insertion is over

Unfortunately that works for the insertion of a small number of items, but it doesn't scale up and i get the mentioned exception.

Am I doing something wrong or it is just a matter of some misconfigured parameter?


Top
 Profile  
 
 Post subject: Re: Session closes while I am inserting data
PostPosted: Fri Mar 05, 2010 5:07 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
can you please post your complete stack trace error.

it looks like a batch problem related, have you taken a look at http://docs.jboss.org/hibernate/stable/ ... batch.html ?

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Session closes while I am inserting data
PostPosted: Fri Mar 05, 2010 5:16 am 
Newbie

Joined: Sun Feb 14, 2010 7:13 pm
Posts: 6
First of all thanks for your quick reply, it is really appreciated.

Here is the full stacktrace
Code:
Exception in thread "main" org.hibernate.SessionException: Session is closed!
   at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72)
   at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1347)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
   at $Proxy17.beginTransaction(Unknown Source)
   at it.polimi.crawler.IEEECrawlerNew.getYearArticles(IEEECrawlerNew.java:166)
   at applications.Crawler.main(Crawler.java:106)


Now I am having a look at the page you suggested. Thanks again for you help.


Top
 Profile  
 
 Post subject: Re: Session closes while I am inserting data
PostPosted: Fri Mar 05, 2010 5:57 am 
Newbie

Joined: Sun Feb 14, 2010 7:13 pm
Posts: 6
Looking at the code I found the cause of the problem, it was on the class that manages the sessions. I was not checking if the session factory returned an already closed session.


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.