-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Session problem
PostPosted: Tue Oct 18, 2005 8:57 am 
Beginner
Beginner

Joined: Tue Aug 30, 2005 9:40 am
Posts: 29
Hi,

We are using a Hibernate in our application the scenario like this

we have two methods one for writing and another for reading data from DB

we am runing thsese two methods in sequence ( I mean one after the another)

The first method is executing without any errors, while second method execution, the following error is throwing.

We are opening and closing the session in each method separately.

Can you throw some light on this

Regads,
Srinivas
----------------------------------------------------------------------------------------

Exception in thread "main" org.hibernate.SessionException: Session is closed
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:131)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:49)
at org.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:24)
at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:271)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1079)
at com.nokia.neosp.server.base.mo.PersonMO.getAttrdetails(PersonMO.java:51)
at com.nokia.neosp.client.PersisterDetails.main(PersisterDetails.java:71)


Top
 Profile  
 
 Post subject: session boundaries
PostPosted: Tue Oct 18, 2005 3:13 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It looks like your attribute 'attrdetails' is mapped as LAZY one and that you use session-per-business transaction pattern (Maybe under the cover, if that is Springs Hibernate wrapper then please stop using it ASAP. ).
If my assumptions are correct then:
in session 1 (read) you have got object that has proxy for attrdetails, not the details. Then method was finished and session got closed.
then session 2 tries to investigate if it needs to preserve attrdetails, and attrdetails proxy tries to use its session reference(to session 1) to get the actual details. Well, at this moment the first session is long gone, hence the exception.

Fixes:
- map attrdetails as eager;
- have read and update as part of one transaction;

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 3:26 pm 
Newbie

Joined: Mon Oct 17, 2005 3:42 pm
Posts: 17
Another thought is that you may need to call 'merge' on the new session in the second method, and make sure that you've got merge cascade enabled on the association.


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