-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 28 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Sun Feb 29, 2004 10:09 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
In conclusion, you're saying "never store hibernate session into http session"?
urgh, have to change my 5% use cases using it.... too bad


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 10:57 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Probaly I too paranoid in this case,
but my coworkers did this mistake a few years ago (I have a lot of bad expierence myself too)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 11:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i thought it was quite "secure" knowing that for the apps i'm talking about, we cannot have simultaneous requests for the same httpSession... i did mistakes and i'll do other... everybody learns


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 12:51 pm 
Beginner
Beginner

Joined: Sat Jan 31, 2004 10:09 am
Posts: 26
baliukas wrote:
Try to implement application without this feature, it is very dangerous too.
It must be more simple to store session state in hashtable (if you use struts then you can use session scope form objects ). It will work as transaction per request for DB, it can break your transaction semantics in theory, but "reconnect" will break it in the same way and it is more diffcult to understand.


I use Tapestry, so I store some session state in the Visit, equals to http session.
You mentioned some risks to store hibernate session in http session. But if we can gurantee there is only one client to use hibernate session and do disconnect or use connection pool. We still can use the session.disconnect() and reconnect() strategy, right?
I you agree this, please continue the following...
Because by using this, hibernate session should be stored in the http session. Each time the request gets in, hibernate session is retrieved from http session, reconnect, and be assigned to threadloacl in servlet or filter. After transaction goes end, hibernate session gets disconnected and put back to http session. Finally set threadloacl to null.
Is this also a solution to use hibernate session?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
that's in parts, what i do when i need more than one request from the same client to manage a long transaction, but it seems this is not ok wait for baliukas or gavin response.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 1:41 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Quote:
Each time the request gets in, hibernate session is retrieved from http session, reconnect, and be assigned to threadloacl in servlet or filter

You need to implement some workaraund to make session thread safe,
user can click the same page twice without waiting the first request to complete (This problem was reported in forum too), frames, dynamic images (charts) can access session concurently, it is possible to prevent, but you must think about it on infrastructure level and it becomes "dangerous". It is very hard to find this kind of bugs, it depends on user input and UI changes can break session managemet.
Session level cache in httpsession is "dangerous" too,
if user closes browser before to complete "transaction" then you have a memory leak, it can produce problems on heavy load and it is amost inpossible to find the cause in production and can be hard to find in tests.

It is not very "bad" and it is possible to find solutions, but this kind of resouce management is "dangerous",
problems can be visible on heavy load and in production only (resource management depends on user input).

It is very easy to live without resouces like cache or connection in httpsession. I think it is a good way store session state on client (hidden form fields) It was very popular in CGI scripts, but it is a good way at this time too, It is more safe and not very hard to use. Hashtable in httpsession leaks memory too, but it is not so "dangerous" in practice if you store user input only without persistent state retrieved from db,
It is more easy to use than form fields on client.



[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 1:49 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
it could be usefull to have an article "why not using httpSession" because if mattjiang and i had the same reflex, many people could do the same "bad practice".
For me it's not so dangerous because it's very rarely used and we are in intranet without complexe frameset can now i understand it can be a disaster if this practice is used too often.

Thanks a lot


Top
 Profile  
 
 Post subject: rtqnnnnnnv
PostPosted: Sun Feb 29, 2004 1:53 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
i7[quote]Each time the request gets in, hibernate session is retrieved from http session, reconnect, and be assigned to threadloacl in servlet or filter[/quote]
You need to implement some workaraund to make session thread safe,
user can click the same page twice without waiting the first request to complete (This problem was reported in forum too), frames, dynamic images (charts) can access session concurently, it is possible to prevent, but you must think about it on infrastructure level and it becomes "dangerous". It is very hard to find this kind of bugs, it depends on user input and UI changes can break session managemet.
Session level cache in httpsession is "dangerous" too,
if user closes browser before to complete "transaction" then you have a memory leak, it can produce problems on heavy load and it is amost inpossible to find the cause in production and can be hard to find in tests.

It is not very "bad" and it is possible to find solutions, but this kind of resouce management is "dangerous",
problems can be visible on heavy load and in production only (resource management depends on user input).

It is very easy to live without resouces like cache or connection in httpsession. I think it is a good way store session state on client (hidden form fields) It was very popular in CGI scripts, but it is a good way at this time too, It is more safe and not very hard to use. Hashtable in httpsession leaks memory too, but it is not so "dangerous" in practice if you store user input only without persistent state retrieved from db,
It is more easy to use than form fields on client.



[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 1:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
In conclusion, you're saying "never store hibernate session into http session"?


I am not. In fact, it is one recommended approach. Juozas has a different view, but personally I just don't find it that problematic to synchronize acces to the HttpSession. You would need to do it anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 2:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Here is a quote from the book:

Code:
There is one final complication. A Hibernate Session is not threadsafe, and the servlet engine
allows multiple requests from the same user to be processed concurrently. So it is possible that
two concurrent requests could obtain the same Hibernate session from the HttpSession if, for
example, the user clicked a submit button twice. This would result in very unpredictable behaviour.
Actually, this problem also affects the previous approach, where we used detached objects,
since detached objects are also not threadsafe. Indeed, this problem affects any web application
which keeps mutable state in the HttpSession! Since this is a generic problem that affects almost
all web applications, we will leave it to you to find an appropriate solution. A good solution
for some applications might simply be to reject any new request if a request is already being processed
for the same user. We could quite easily implement this in a servlet filter. Other applications
might need to serialize requests from the same user (which can be achieved by synchronizing
upon the HttpSession object in a servlet filter).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 2:43 pm 
Beginner
Beginner

Joined: Sat Jan 31, 2004 10:09 am
Posts: 26
Quote:
You need to implement some workaraund to make session thread safe


I agree with baliukas. User really might send second request to server by click submit twice before first request completes process. I think I know what "dangerous" means now...

But gavin seems to support storing hibernate session in http session. Besides thread safe consideration, user clicks submit twice or closes browser. There are critical points to be considered. May gavin give us some guides to store hibernate session in http session?

thank you all very much.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 3:10 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
gavin wrote:
Here is a quote from the book:
A good solution
for some applications might simply be to reject any new request if a request is already being processed
for the same user.


i'll use this solution, i will cover the risk for my apps

thanks a lot, i'm looking forward to read Hibernate in action in august.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 11:56 pm 
Beginner
Beginner

Joined: Sat Jan 31, 2004 10:09 am
Posts: 26
Thanks for all your help.
I learned a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 28 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.