-->
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.  [ 5 posts ] 
Author Message
 Post subject: Caused by: org.hibernate.SessionException: Session is closed
PostPosted: Sat Jun 17, 2006 12:41 am 
Newbie

Joined: Thu Jun 15, 2006 10:36 am
Posts: 4
Hi
I am doing JNDI BINDING of hibernate sessionfactory and using that sessionFactory instance to create session for my web applciation.
I am getting exception:Session is closed!

I searched on net and found its a bug:JBAS-2707 in JBoss Application Server for HibernateIntgUnitTestCase Failure.It has been resolved:

Code:
Affects Version/s: JBossAS-4.0.4RC1, JBossAS-4.0.4.CR2
Fix Version/s: JBossAS-5.0 Alpha, JBossAS-4.0.4RC1, JBossAS-4.0.4.CR2


I have downloaded new installer:jboss-4.0.4.GA-Patch1-installer.jar

But issue is not resolved with that version also...

Please help...........

Code:

Caused by: org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1610)
at .................................................


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 17, 2006 2:04 am 
Newbie

Joined: Mon May 29, 2006 12:57 am
Posts: 11
Location: india
Session is closed error is thrown when you try to access a hibernate session variable after you have closed it. Session variables imply all the instances of your beans whcih are loaded to a new session which is created once you fire a DB query.

Make sure you are not trying to access the DB after you have closed the hibernate session.

This may happen if you have loaded your beans from the DB and after closing the session try to access an attribute which may not have loaded when you accessed the DB. As soon as you fire a getX() for that x atribute, hibernate will fire a query to the DB to get the x internally which will fail since your session is closed.

This generally happens in a multi-layered environment.


Top
 Profile  
 
 Post subject: session is closed!!
PostPosted: Sat Jun 17, 2006 2:52 am 
Newbie

Joined: Thu Jun 15, 2006 10:36 am
Posts: 4
hi,

My application working fine if i am not getting session factory from Jndi.
Using hibernate.cfg.xml and loading configuration,if i do then there is no problem.
But now i have jndi bounded hibernate session factory and placed that configuration file and all .hbm.xml and java objects in har archive and that is palced in ear which contains my application war.
Structure of my ear:

.har(hibernate jndi bind config.xml,.hbm.xml and business objects)
.war(application war file)
.jar(common libraries-it contains all the jars and my applications classes)

It has been deployed successfully and my web application's first login page is opened.

No session close is done explicitly....

please help


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 18, 2006 8:28 pm 
Newbie

Joined: Thu Mar 30, 2006 9:21 pm
Posts: 11
Hi, not sure if this will help or not ;-)

I encountered the same problem with a web app where I was getting messages about the session being closed. The problem was occuring when the system (Using Spring and Hibernate) was attempting render the page to be sent back to the user.

I have lazy loading active so hibernate was not grabbing stuff from the database until it was accessed and many POJO properties are not accessed until they are needed for displaying data to the user. So basically the hibernate sesion was closing after the controller code had run, but then whilst rendering the web page, previously un-accessed properties where causing hibernate to try and obtian further data from the database, hence the error messages.

The solution was to enable an Interceptor which takes control of the hibernate sessions and keeps them open right to the end of the request. This means that once out of the spring controller and when rendering the web page for the user, hibernate is still available for further querying if needed.

Read http://www.jroller.com/page/kbaum?entry=orm_lazy_initialization_with_dao
For a detailed example.

_________________
Derek Clarkson
Analyst Programmer
Aegeon Pty Ltd
Melbourne Australia


Top
 Profile  
 
 Post subject: I have used Phaselistener
PostPosted: Mon Jun 19, 2006 1:56 am 
Newbie

Joined: Thu Jun 15, 2006 10:36 am
Posts: 4
Hi drekka,

I am using PhaseListener and when my whole page get rendered then in method:void afterPhase(PhaseEvent arg0) : i am closing the hibernate session.So this assures us that session is closed only after our page get rendered.So now can u tell the reason why its is happening?

Thanks a lot


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