-->
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.  [ 11 posts ] 
Author Message
 Post subject: CMT SSLB and Session
PostPosted: Fri Jul 30, 2004 10:13 pm 
Newbie

Joined: Sat Jul 24, 2004 10:10 am
Posts: 15
Hibernate 2.1.4 , Jboss 3.2.5

I have developed an application consisting of SSLB using Hibernate as the persistence layer. Each method in the SSLB uses the ThreadLocal pattern to get the session and close the session in the finally clause.

When a method doSomething() in SSLB1 calls method doThat() in SSLB2,
I get the following error : 'Session is closed'. How do I use the ThreadLocal pattern for nested calls?

Please advise.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 01, 2004 8:01 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
How are you flushing and closing sessions? In each method?

What is your EJB transaction type?


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 01, 2004 9:40 am 
Newbie

Joined: Sat Jul 24, 2004 10:10 am
Posts: 15
The EJB's are container managed. The sessions are flushed in each
method.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 01, 2004 9:51 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is more difficult than it sounds. Some application servers (like JBoss) virtually guarantee that all EJB calls on the same node are made inside the same thread (pass by reference semantics). Others don't. I don't use much EJBs these days, so I would be interested in a solution or final answer to this question.

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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 01, 2004 10:09 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
jdoe7890 wrote:
The EJB's are container managed. The sessions are flushed in each method.


With ThreadLocal and calling multiple session bean methods, you have to have the current session be aware of the depth of the transaction calls (one transaction calls another. See Steve Ebersole's variation at http://www.hibernate.org/42.html.

Also check out http://www.jboss.org/wiki/Wiki.jsp?page=JBossHibernate. I haven't used the new stuff in JBoss 3.2.6 yet, but it look interesting.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 01, 2004 11:07 am 
Newbie

Joined: Sat Jul 24, 2004 10:10 am
Posts: 15
Thanks for the replies.

a) Is Steve Ebersole's approach safe? I am surprised that developers have not faced this common problem of nested CMT SSLB calls with Hibernate. The excellent book 'Hibernate in Action' does not have any references to this common problem.

b) Spring has inbuild support for sessions and transactions. Our project is not yet ready to tackle another framework.

c) I am interested in an appserver independent pattern for nested calls and session management.

My methods in the EJB's are

doSomething()
{
Session session = null ;

try
{

session = HibernateUtil.getSesssion() // ThreadLocal pattern

........ business logic ....

}
catch( Exception ex}
{

}
finally
{
HibernateUtil.closeSession();
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 01, 2004 11:34 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
As Christian notes, ThreadLocal works only for app servers that ensure a single thread through a transaction. I don't know what an app server independent solution would look like.

Steve's solution is safe if you ensure that you have your "open/closeSession" balanced, which finally helps with. There is nothing Spring specific in that.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 9:57 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
One of ways is to use custom proxy for SSLB and all app servers ensure a single thread through a transaction, I do not know broken servers, but do not care about broken server it does not work any way.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:03 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
BTW see this code http://voruta.sourceforge.net/xref/samples/ejb/, implementation can be broken, but idea must be clear.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 12:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The conclusion I eventually came to is that nested ejb calls (at least prior to EJB 3) is a broken design. I wrote that wiki page when the architecture I was working on at that time did just that. But its not the right way to do this. The ejbs should simply delegate to classes which implement the actual functionality.

The code I wrote on the wiki does work as long as opens and closes are balanced like sgwood mentioned. If you are using JBoss and have the ability to upgrade to 3.2.6, use the session management stuff there instead. I (along with others) wrote that stuff also and it will work much better (re: more safely).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 1:25 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
" The ejbs should simply delegate to classes which implement the actual functionality. "
This is recommended for all of RPC types, implement the actual functionality and generate RPC wrapper later, I prefer dynamic wrappers, but source code generation or templates like ATL was popular for C++ code in DCOM and CORBA too.


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