You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Benedict <pb...@apache.org> on 2009/02/25 06:45:34 UTC

Hibernate, HTTP Session, and LazyInitializationException

Does anyone have a good solution for objects stored in an HTTP Session
that should be reattached per request? For example, like the
authenticated "user" object stored in the HTTP Session.

I had a servlet filter written that attached the entity per request,
but a double-click from the user showed the futility of that approach.
You can't have one entity attached to two sessions :-)

And, I don't think it's a GOOD idea for struts code to know anything
about Hibernate. So I want to do be able to the reattachment
transparently to UI/Web code.

Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Hibernate, HTTP Session, and LazyInitializationException

Posted by Antonio Petrelli <an...@gmail.com>.
2009/2/25 Paul Benedict <pb...@apache.org>:
> I had a servlet filter written that attached the entity per request,
> but a double-click from the user showed the futility of that approach.
> You can't have one entity attached to two sessions :-)

Uh sorry I did not read correctly this sentence.
You are right, the same object is at risk of being attached twice,
even with OSIV filter.
Probably the best thing is to attach the object only when needed.
The typical case is when you are constructing an object through
various steps. So you:
1. load an object, with all the needed relations;
2. detach the object;
3. modify the objects in your pages;
4. when you need to save it:
  a. use "redirect after post" and tokens to avoid double submit;
  b. reattach the object;
  c. save.

HTH
Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Hibernate, HTTP Session, and LazyInitializationException

Posted by Antonio Petrelli <an...@gmail.com>.
2009/2/25 Paul Benedict <pb...@apache.org>:
> Does anyone have a good solution for objects stored in an HTTP Session
> that should be reattached per request? For example, like the
> authenticated "user" object stored in the HTTP Session.
>
> I had a servlet filter written that attached the entity per request,
> but a double-click from the user showed the futility of that approach.
> You can't have one entity attached to two sessions :-)

The easier approach in Open Session In View:
http://www.hibernate.org/43.html
Spring has already an implementation:
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html

HTH
Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Hibernate, HTTP Session, and LazyInitializationException

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
This has nothing to do with the original posting. Please post your
question creating a new thread/email.

Nils-H

On Thu, Feb 26, 2009 at 8:12 AM, suhas kokal <ko...@yahoo.com> wrote:
> Hi all,
>
> If some body knows hot to use javascript alerts with struts 2.0 (when validation framework fires)please find me the way.
>
> Thanks a lot in advance.
>
> Suhas.
>
>
> --- On Wed, 25/2/09, Paul Benedict <pb...@apache.org> wrote:
>
>> From: Paul Benedict <pb...@apache.org>
>> Subject: Hibernate, HTTP Session, and LazyInitializationException
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Date: Wednesday, 25 February, 2009, 11:15 AM
>> Does anyone have a good solution for objects stored in an
>> HTTP Session
>> that should be reattached per request? For example, like
>> the
>> authenticated "user" object stored in the HTTP
>> Session.
>>
>> I had a servlet filter written that attached the entity per
>> request,
>> but a double-click from the user showed the futility of
>> that approach.
>> You can't have one entity attached to two sessions :-)
>>
>> And, I don't think it's a GOOD idea for struts code
>> to know anything
>> about Hibernate. So I want to do be able to the
>> reattachment
>> transparently to UI/Web code.
>>
>> Paul
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail:
>> user-help@struts.apache.org
>
>
>      Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Hibernate, HTTP Session, and LazyInitializationException

Posted by John Dell'Aera <de...@hotmail.com>.
Hello.
Force a round trip on the first request, prior to authentication,
and place the authenticated user object in the session object.
All future requests prior to session timeout will be tied to the same 
session,
and can therefore be serviced by the same session object.
John


--------------------------------------------------
From: "suhas kokal" <ko...@yahoo.com>
Sent: Wednesday, February 25, 2009 11:12 PM
To: "Struts Users Mailing List" <us...@struts.apache.org>
Subject: Re: Hibernate, HTTP Session, and LazyInitializationException

> Hi all,
>
> If some body knows hot to use javascript alerts with struts 2.0 (when 
> validation framework fires)please find me the way.
>
> Thanks a lot in advance.
>
> Suhas.
>
>
> --- On Wed, 25/2/09, Paul Benedict <pb...@apache.org> wrote:
>
>> From: Paul Benedict <pb...@apache.org>
>> Subject: Hibernate, HTTP Session, and LazyInitializationException
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Date: Wednesday, 25 February, 2009, 11:15 AM
>> Does anyone have a good solution for objects stored in an
>> HTTP Session
>> that should be reattached per request? For example, like
>> the
>> authenticated "user" object stored in the HTTP
>> Session.
>>
>> I had a servlet filter written that attached the entity per
>> request,
>> but a double-click from the user showed the futility of
>> that approach.
>> You can't have one entity attached to two sessions :-)
>>
>> And, I don't think it's a GOOD idea for struts code
>> to know anything
>> about Hibernate. So I want to do be able to the
>> reattachment
>> transparently to UI/Web code.
>>
>> Paul
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail:
>> user-help@struts.apache.org
>
>
>      Add more friends to your messenger and enjoy! Go to 
> http://messenger.yahoo.com/invite/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Hibernate, HTTP Session, and LazyInitializationException

Posted by suhas kokal <ko...@yahoo.com>.
Hi all,

If some body knows hot to use javascript alerts with struts 2.0 (when validation framework fires)please find me the way.

Thanks a lot in advance.

Suhas.


--- On Wed, 25/2/09, Paul Benedict <pb...@apache.org> wrote:

> From: Paul Benedict <pb...@apache.org>
> Subject: Hibernate, HTTP Session, and LazyInitializationException
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Wednesday, 25 February, 2009, 11:15 AM
> Does anyone have a good solution for objects stored in an
> HTTP Session
> that should be reattached per request? For example, like
> the
> authenticated "user" object stored in the HTTP
> Session.
> 
> I had a servlet filter written that attached the entity per
> request,
> but a double-click from the user showed the futility of
> that approach.
> You can't have one entity attached to two sessions :-)
> 
> And, I don't think it's a GOOD idea for struts code
> to know anything
> about Hibernate. So I want to do be able to the
> reattachment
> transparently to UI/Web code.
> 
> Paul
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org


      Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org