T5: HibernateSessionManagerImpl should close session on thread cleanup?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

T5: HibernateSessionManagerImpl should close session on thread cleanup?

lasitha
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@...%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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

lasitha
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 <[hidden email]> 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@...%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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

joshcanfield-2
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 <[hidden email]> 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 <[hidden email]> 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@...%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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
Reply | Threaded
Open this post in threaded view
|

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

Massimo Lusetti
On 9/20/07, Josh Canfield <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Thiago H de Paula Figueiredo
On Thu, 20 Sep 2007 04:37:12 -0300, Massimo Lusetti <[hidden email]>  
wrote:

> On 9/20/07, Josh Canfield <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Massimo Lusetti
On 9/20/07, Thiago H de Paula Figueiredo <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Thiago H de Paula Figueiredo
On Thu, 20 Sep 2007 10:44:31 -0300, Massimo Lusetti <[hidden email]>  
wrote:

> On 9/20/07, Thiago H de Paula Figueiredo <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]