beehive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Murray" <>
Subject RE: Hibernate Goodies
Date Thu, 09 Dec 2004 13:55:41 GMT
Is this control using the basic ThreadLocal pattern or the improved model?
The basic ThreadLocal pattern has been known to fail in EJB environments.
There is a better version that ensures that the session does not get closed

The code examples in they have are a bit incomplete and need a little
tweaking, but the concept will get you out of this malaise.

John Murray
Sobetech, Inc.

-----Original Message-----
From: Dan Diephouse []
Sent: Wednesday, December 08, 2004 10:46 PM
To: Beehive Users
Subject: Re: Hibernate Goodies

Hi Adrian,

You are correct in your understanding of how the control *should* work.
A session is associated with a Thread so each time you get a new servlet
request your session is created and closed at the end.  You should not
have to call reconnect or disconnect. Your code looks exactly right.

I'm going to guess that you're using the alpha-1 distribution which may
have a bug in it.  Can you try a snapshot jar that I posted today?

I've created an application with this so I know it works.  I will be
posting this demo within the next day or two to show how this works.
Please let me know if this works for you.
- Dan

Adrian Grealish wrote:

>I have got my beehive web application to use the Hibernate control but I
>am running into a problem with the Hibernate session being closed for
>subsequent requests. Works for one call only.
>>From reading the tutorial I thought the session was associated with the
>ThreadLocal and will be created/opened on request. I'm confused about
>what to do with the session once it's been used. From reading the
>tutorial we don't have to close the session as the control manages that.
>The next time I call my control I get a session is closed exception.
>I've included my code in it's simplest form below, should I be checking
>to see if the session is closed and calling reconnect each time? Doesn't
>this defeat the point of using the ThreadLocal?
>What am I missing here?
>public class TestOwnersSessionImpl implements TestOwnersSession
>    @org.apache.beehive.controls.api.context.Context ControlBeanContext
>    @org.apache.beehive.controls.api.context.Context ResourceContext
>    @Control
>    HibernateControl hibernate;
>    public List selectTestOwners() {
>    	List testOwners = null;
>    	try {
>    		Session session = hibernate.getSession();
>    		testOwners = session.find("from TestOwner");
>    	}catch(HibernateException ex) {
>    		System.err.print(ex.getMessage());
>    		ex.printStackTrace(System.err);
>    	}
>    	return testOwners;
>    }
>-----Original Message-----
>From: Dan Diephouse []
>Sent: Monday, December 06, 2004 1:10 PM
>Subject: Hibernate Goodies
>Howdy all,
>I know there are hibernate users out there and I would like to invite
>you test the hibernate control.  I've just added in managed
>transactions, so the control will take care of starting/committing your
>transactions as well as session management.  I look forward to any
>feedback that you have (on documentation, code, api, etc)!
>Snapshot jar:
>(you should just need to drop this into your build to be able to use it.
>For the hibernate dependencies see the hibernate documentation.)
>- Dan

Dan Diephouse
Envoi Solutions LLC

View raw message