You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by lasitha <la...@gmail.com> on 2007/09/18 16:48:05 UTC

T5: HibernateSessionManagerImpl should close session on thread cleanup?

Hello all.

Back in June (23rd), Bill Holloway solved an 'illegal attempt to
associate a collection with two open sessions' hibernate exception by
using merge() after reattaching a detached object:
Re: T5 Creating new hibernate persistent entity via beaneditform
http://mail-archives.apache.org/mod_mbox/tapestry-users/200706.mbox/%3c49f89bdf0706222248s6e6b932eu3fb2fec394a69f1a@mail.gmail.com%3e

I wasn't quite convinced with this because that exception (though
often maligned!) is usually quite accurate.  Moreover, if there were
two sessions in play, using merge() would effectively _avoid_ the
issue by hydrating a new _copy_ of the (supposedly) detached object.

So i've been digging around (since, rather inevitably, i'm also seeing
this exception), and i don't see where the HibernateSessionManagerImpl
is actually _closing_ the thread local session...

What am i missing?  It seems unlikely we've been geting away with not
closing sessions.  Where might this be happening?

To test the theory i patched HibernateSessionManagerImpl to close the
session immediately after committing:
public void threadDidCleanup() {
    _transaction.commit();
    _session.close();
}

This gets rid of my 'illegal attempt...' exceptions!

Any insight appreciated.
Thanks,
lasitha.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: HibernateSessionManagerImpl should close session on thread cleanup?

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 20 Sep 2007 10:44:31 -0300, Massimo Lusetti <ml...@gmail.com>  
wrote:

> On 9/20/07, Thiago H de Paula Figueiredo <th...@gmail.com> wrote:
>
>> Shameless plug: take a look at
>> http://tapestry-mine.sourceforge.net/hibertapestry/ :)
>
> Commit the source in your repo ... or even better fire a bug with
> enhancement patches on JIRA :)

I'll commit the sources this weekend, improve the documentation, and  
provide some examples.
I don't think I'll send patches because HiberTapestry is not based on  
Tapestry5-Hibernate. I tried to use the latter, but it didn't provide me  
all the features I wanted. They have different architectures. As we're  
talking about open-source, I created a new project. If somebody asks me to  
contribute it to the Tapestry project, I'll do it. :)

-- 
Thiago H. de Paula Figueiredo
Desenvolvedor, Instrutor e Consultor de Tecnologia
Eteg Tecnologia da Informação Ltda.
http://www.eteg.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: HibernateSessionManagerImpl should close session on thread cleanup?

Posted by Massimo Lusetti <ml...@gmail.com>.
On 9/20/07, Thiago H de Paula Figueiredo <th...@gmail.com> wrote:

> Shameless plug: take a look at
> http://tapestry-mine.sourceforge.net/hibertapestry/ :)

Commit the source in your repo ... or even better fire a bug with
enhancement patches on JIRA :)

Ciao
-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: HibernateSessionManagerImpl should close session on thread cleanup?

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 20 Sep 2007 04:37:12 -0300, Massimo Lusetti <ml...@gmail.com>  
wrote:

> On 9/20/07, Josh Canfield <jo...@thedailytube.com> wrote:

> I agree that Hibernate support needs some work but at least is usable.

Shameless plug: take a look at  
http://tapestry-mine.sourceforge.net/hibertapestry/ :)
It implments the open session in view design pattern, automatically closes  
the Session in thread cleanup and does automatic transaction opening and  
commiting (and aborting, if some exception is thrown) based on annotations  
in your service methods. ;)
In your code that use Sessions, just inject it through Tapestry-IoC.

-- 
Thiago H. de Paula Figueiredo
Desenvolvedor, Instrutor e Consultor de Tecnologia
Eteg Tecnologia da Informação Ltda.
http://www.eteg.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: HibernateSessionManagerImpl should close session on thread cleanup?

Posted by Massimo Lusetti <ml...@gmail.com>.
On 9/20/07, Josh Canfield <jo...@thedailytube.com> wrote:

> I had to add rollback logic to the HibernateSessionManager, but I didn't add
> a close. I haven't seen the exception you are reporting, but I don't know
> hibernate well enough to say definitively that this is ok. The session is
> marked to close with the transaction commit/rollback, but I didn't see it
> get closed when stepping through in the debugger.

Looking at this[1] and googling a bit could help you. Tapestry
Hibernate integration is and implementation of the classical "Open
Session in View" pattern so the session is typically closed when it's
GC but this is very very very dependant on your Hibernate
configuration.

Search on [1] for "Can I commit the transaction before rendering the
view?" and dig through hibernate doc[2].

I agree that Hibernate support needs some work but at least is usable.
I was tempted to add try/catch/finally logic to
HibernateSessionManagerImpl to do classical commit/rollback/close but
resisted since anyway it is called during ThreadCleanup which to me
seems to late to do any repair work on the view.


[1]
http://www.hibernate.org/43.html
[2]
http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html
-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: HibernateSessionManagerImpl should close session on thread cleanup?

Posted by Josh Canfield <jo...@thedailytube.com>.
I had to add rollback logic to the HibernateSessionManager, but I didn't add
a close. I haven't seen the exception you are reporting, but I don't know
hibernate well enough to say definitively that this is ok. The session is
marked to close with the transaction commit/rollback, but I didn't see it
get closed when stepping through in the debugger.

On 9/19/07, lasitha <la...@gmail.com> wrote:
>
> Hate to bump my own thread, but i'd really like some feedback before i
> post a bug on jira.
> If i'm not mistaken, this will be a problem for anyone using
> tapestry-hibernate.
>
> Summary: I think HibernateSessionManagerImpl needs to be closing
> sessions on thread cleanup.
>
> On 9/18/07, lasitha <la...@gmail.com> wrote:
> > Hello all.
> >
> > Back in June (23rd), Bill Holloway solved an 'illegal attempt to
> > associate a collection with two open sessions' hibernate exception by
> > using merge() after reattaching a detached object:
> > Re: T5 Creating new hibernate persistent entity via beaneditform
> >
> http://mail-archives.apache.org/mod_mbox/tapestry-users/200706.mbox/%3c49f89bdf0706222248s6e6b932eu3fb2fec394a69f1a@mail.gmail.com%3e
> >
> > I wasn't quite convinced with this because that exception (though
> > often maligned!) is usually quite accurate.  Moreover, if there were
> > two sessions in play, using merge() would effectively _avoid_ the
> > issue by hydrating a new _copy_ of the (supposedly) detached object.
> >
> > So i've been digging around (since, rather inevitably, i'm also seeing
> > this exception), and i don't see where the HibernateSessionManagerImpl
> > is actually _closing_ the thread local session...
> >
> > What am i missing?  It seems unlikely we've been geting away with not
> > closing sessions.  Where might this be happening?
> >
> > To test the theory i patched HibernateSessionManagerImpl to close the
> > session immediately after committing:
> > public void threadDidCleanup() {
> >     _transaction.commit();
> >     _session.close();
> > }
> >
> > This gets rid of my 'illegal attempt...' exceptions!
> >
> > Any insight appreciated.
> > Thanks,
> > lasitha.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

Re: T5: HibernateSessionManagerImpl should close session on thread cleanup?

Posted by lasitha <la...@gmail.com>.
Hate to bump my own thread, but i'd really like some feedback before i
post a bug on jira.
If i'm not mistaken, this will be a problem for anyone using tapestry-hibernate.

Summary: I think HibernateSessionManagerImpl needs to be closing
sessions on thread cleanup.

On 9/18/07, lasitha <la...@gmail.com> wrote:
> Hello all.
>
> Back in June (23rd), Bill Holloway solved an 'illegal attempt to
> associate a collection with two open sessions' hibernate exception by
> using merge() after reattaching a detached object:
> Re: T5 Creating new hibernate persistent entity via beaneditform
> http://mail-archives.apache.org/mod_mbox/tapestry-users/200706.mbox/%3c49f89bdf0706222248s6e6b932eu3fb2fec394a69f1a@mail.gmail.com%3e
>
> I wasn't quite convinced with this because that exception (though
> often maligned!) is usually quite accurate.  Moreover, if there were
> two sessions in play, using merge() would effectively _avoid_ the
> issue by hydrating a new _copy_ of the (supposedly) detached object.
>
> So i've been digging around (since, rather inevitably, i'm also seeing
> this exception), and i don't see where the HibernateSessionManagerImpl
> is actually _closing_ the thread local session...
>
> What am i missing?  It seems unlikely we've been geting away with not
> closing sessions.  Where might this be happening?
>
> To test the theory i patched HibernateSessionManagerImpl to close the
> session immediately after committing:
> public void threadDidCleanup() {
>     _transaction.commit();
>     _session.close();
> }
>
> This gets rid of my 'illegal attempt...' exceptions!
>
> Any insight appreciated.
> Thanks,
> lasitha.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org