Re: Struts 2 hibernate session-per-request

2008-06-17 Thread Laurie Harper

Márcio Gurgel wrote:

Hi Everyone,

Some time ago I asked you about a problem with old objects in session.
I noted that my application is using diferent sessions to recovery a data
from db.
Some times the application shows the corect result, other shows old results
(with old session).

I guess that if I use session-per-request I'll throw my problem away.

Does anyone knows how to implement a session-per-request in Struts 2?


The term 'session-per-request' doesn't really make a lot of sense, 
unless you are using 'session' to mean something other than a web 
application session (perhaps a database 'session'? a Hibernate session? 
something else?).


IIRC, though, your previous problem *was* about web application 
sessions, as in unwanted sharing of session-scoped data. Perhaps you 
could explain what you mean by session-per-request?


L.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts 2 hibernate session-per-request

2008-06-17 Thread Al Sutton
I think he's trying to do whats at 
http://cwiki.apache.org/S2WIKI/struts-2-spring-2-jpa-ajax.html without 
using the great google first :).


Al.

Laurie Harper wrote:

Márcio Gurgel wrote:

Hi Everyone,

Some time ago I asked you about a problem with old objects in session.
I noted that my application is using diferent sessions to recovery a 
data

from db.
Some times the application shows the corect result, other shows old 
results

(with old session).

I guess that if I use session-per-request I'll throw my problem away.

Does anyone knows how to implement a session-per-request in Struts 2?


The term 'session-per-request' doesn't really make a lot of sense, 
unless you are using 'session' to mean something other than a web 
application session (perhaps a database 'session'? a Hibernate 
session? something else?).


IIRC, though, your previous problem *was* about web application 
sessions, as in unwanted sharing of session-scoped data. Perhaps you 
could explain what you mean by session-per-request?


L.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts 2 hibernate session-per-request

2008-06-17 Thread Antonio Petrelli
2008/6/17 Márcio Gurgel [EMAIL PROTECTED]:
 Does anyone knows how to implement a session-per-request in Struts 2?

If you mean a Hibernate session, you have to implement the Open
Session In View pattern, for example using a filter.
http://www.hibernate.org/43.html

If you are using Spring, there is an already implemented
OpenSessionInView filter:
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html

Antonio

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts 2 hibernate session-per-request

2008-06-17 Thread Márcio Gurgel
I'm gonna try your sugestions and post the result.

Thanks a lot!

Márcio Gurgel

2008/6/17 Antonio Petrelli [EMAIL PROTECTED]:

 2008/6/17 Márcio Gurgel [EMAIL PROTECTED]:
  Does anyone knows how to implement a session-per-request in Struts 2?

 If you mean a Hibernate session, you have to implement the Open
 Session In View pattern, for example using a filter.
 http://www.hibernate.org/43.html

 If you are using Spring, there is an already implemented
 OpenSessionInView filter:

 http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html

 Antonio

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




RE: Struts and Hibernate Session

2004-05-05 Thread Marco Mistroni
Hi,
My 2 cents
I have written an app running on jboss that uses hibernate.
The code that uses hibernate is embedded in a plugin, and a
Session is open and closed after every request

I m also waiting for suggestion on the topic :-)

Regards
marco



-Original Message-
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Lionel
Sent: 05 May 2004 11:31
To: [EMAIL PROTECTED]
Subject: Struts and Hibernate Session

Hi !

I use struts 1.2 and Hibernate on Websphere 5.
I use the struts plugin to store the SessionFactory on applicaiton
context.

Where is the best way to keep the current opened Hibernate Session ?
-in the HttpSession of each user ?
-in a singleton ?
-...

When to close this Session ?
-after each request ?
-when the HttpSession closes ?
-...

Acutally, I have put the getHibernateSession() on a ActionFormBase.
After each SQL action (load, find...) I close the Session.
I don't believe this is a good design and would like to improve it.

Thanks for your advices...

Lionel




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts and Hibernate Session

2004-05-05 Thread Lionel
Joe Germuska wrote:

 Acutally, I have put the getHibernateSession() on a ActionFormBase.
 After each SQL action (load, find...) I close the Session.
 I don't believe this is a good design and would like to improve it.

 This is actually how Hibernate is meant to be used.  The session
 lifespan is supposed to approximate that of a transaction.

The problem is that when I load an object, put the object into HttpSession,
close the hibernate Session.
If later I call a getter on lazy loaded children, I get a LazyException,
connection closed
I want to keep the children lazy loaded because I scarcely need them.

The only solution I found is to open a new Session, reload the object, and
then load the children...




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts and Hibernate Session

2004-05-05 Thread Joe Germuska
At 2:10 PM +0200 5/5/04, Lionel wrote:
Nicolas de Amorrortu wrote:
 Have you tried the following? http://www.hibernate.org/43.html.
this is what I was thinking about when I posted my question...but haven't
tried it yet.
I don't think it will solve my problem as the object I load is put in
session and can be accessed many requests later...
That solution offers no help to beans which span multiple HTTP requests.

At 1:57 PM +0200 5/5/04, Lionel wrote:
The problem is that when I load an object, put the object into HttpSession,
close the hibernate Session.
If later I call a getter on lazy loaded children, I get a LazyException,
connection closed
I want to keep the children lazy loaded because I scarcely need them.
The only solution I found is to open a new Session, reload the object, and
then load the children...
I'm not a Hibernate expert by any means, but I think you would just 
have to code around it.  I've seen lots of things suggesting that 
holding on to a Hibernate session for too long causes its own 
problems, and if you scarcely need the children, you can probably 
afford the overhead to get them explicitly when you need them.

Joe
--
Joe Germuska
[EMAIL PROTECTED]  
http://blog.germuska.com
  Imagine if every Thursday your shoes exploded if you tied them 
the usual way.  This happens to us all the time with computers, and 
nobody thinks of complaining.
-- Jef Raskin

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]