-->
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.  [ 8 posts ] 
Author Message
 Post subject: best practice to share hibernate session on web app
PostPosted: Mon Nov 05, 2007 10:36 am 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
Helloo,

Id like to get your opinion for the best way to use hibernate spring and JSf web app,
I have 2 separate project, the first one, use hibernate and spring to manage DAO objects; the second is the JSF web app,
the application context file is stored on the hibernate project, so on the web app I just do like that:

Code:
MyBean = ServiceLocator.getMyBeanService().finById(id);


hollowing out, the hibernate session is not saved between 2 calls, It would be a bite slowly..
what's the best ay to share hibernate session and let the projects independents.?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 4:09 am 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
no idea..???


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 5:12 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
never keep database (or any other restricted) resources open in between http requests.
It's a recipe for disaster.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 5:21 am 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
so , open/close hibernate session for each data babse call does not reduce performance??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 7:55 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
if you use connection pooling it should be minimal.
And you're saving yourself a lot of headaches with connection starvation if your load goes up or clients don't close their sessions properly (most users tend to just close their browser window rather than use your "logout" button to tell the server they're done).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 1:25 pm 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
jwenting wrote:
if you use connection pooling it should be minimal.
And you're saving yourself a lot of headaches with connection starvation if your load goes up or clients don't close their sessions properly (most users tend to just close their browser window rather than use your "logout" button to tell the server they're done).

Im using spring with hibernate.
I talk about hibernate session..I dont manage connection pooling..
on the web app i cannot even use the dynamic feetching..so, I dont take advantage of persistence..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 3:55 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
Either Spring or Hibernate can provide your connection pool.
A Hibernate session is linked to a database connection, you don't want to hold onto that connection any longer than absolutely necessary.

If you configure a connection pool the performance penalty for closing the connection in between http requests should be minimal.

I've seen the results of applications holding on to connections too long. Connection starvation causes database servers to hang or crash, sometimes with disastrous results (loss of data integrity, but far more frequently "just" lost productivity and frustrated DBAs and system administrators).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 8:36 am 
Beginner
Beginner

Joined: Wed May 23, 2007 1:07 pm
Posts: 28
Just take a look at the open session in view pattern:

http://www.hibernate.org/43.html

Basically, in a web app what you want is to create one session factory and then open and close sessions on each request. Connection pooling takes care of leaving enough connections to your database so that performance is good.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.