-->
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.  [ 4 posts ] 
Author Message
 Post subject: web application and hibernate session handling
PostPosted: Thu Dec 16, 2004 7:24 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Having read the document over layered architecture and session handling, I am still quite unsure how to use Hibernate in my web application.

At the moment I disconnect the session which has the effect that I am having a new session for each web request. I expect to get memory problems under traffic, when I do not properly close the session.

At the moment, I see two choices (please correct me, if I am wrong)
1)
Saving the hibernate session in the session
a) disconnection and reconnection
b) keeping it alive
and reusing it by this procedure
2)
Closing the session
This means that in each request I copy the Data from a Hibernate List to a Normal java.util List to decouple it from the database.
3)
Learning and understanding the stuff with the detached objects. (Here I do not understand how to detach a Hibernate List).

At the moment I think to use number 1 as I expect it to be faster as number 2. Am i right with the alternatives? What do you consider to be the best way?
Thank you for all ideas.

Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 7:40 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"2)" (session/transaction per request) is the right way, but you do not need to copy any lists. If you need cache then use JVM level cache for this optimization. "Fat" objects in httpsession produce many problems : synchronization and memory leaks, random data from different caches (sessions), it will complicate load balancing too.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 9:38 am 
Newbie

Joined: Fri Jul 15, 2005 6:35 am
Posts: 12
What do you mean with:
"If you need cache then use JVM level cache for this optimization" ?

Coping data from lists seems to be necessary.
What is the best way for solve this problem ?

What about lazy fatching of associations ?
If I close the session, when I try to access a associated class, hibernate throw an Exception (it says that the connection is closed).

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 10:15 am 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
Quote:
What about lazy fatching of associations ?
If I close the session, when I try to access a associated class, hibernate throw an Exception (it says that the connection is closed).


The way I understand this (I've been trying to understand how to do some of this for a while, too) is that you need to fully initialize whatever you want to send to the client side before closing the session. This would commonly be done by using fetching strategies in the Query (part of the HQL itself)/Criteria APIs or by simply "walking" the object graph before you send it.

What I am unsure about is whether the retrieved entities (after the session is closed they "become" detached entities) are Serializable. If I understand all of this, if they are serializable as POJOs (when used outside of hibernate, that is), then the proxies that hibernate generates will also be Serializable. Of course, if the client calls a getter on a lazy-loaded property that is not initialized, you will get a LazyInitializationException, but this is why you have to make sure you've initialized everything you want to use before closing the session.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

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.