-->
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.  [ 6 posts ] 
Author Message
 Post subject: Open Session in View pattern and DB Connection pooling
PostPosted: Fri Jul 09, 2004 5:12 pm 
Newbie

Joined: Wed May 12, 2004 2:57 pm
Posts: 17
Hi all,

I am implementing Open Session in View pattern in a struts application and using DBCP pool for connection pooling.

My question is: Does a Hibernate Session holds the same database connection for the Session's life time or does it open and close a connection from the pool during each Transaction?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A Session uses a single JDBC Connection (unless you disconnect() or reconnect() it, of course).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 5:21 pm 
Newbie

Joined: Wed May 12, 2004 2:57 pm
Posts: 17
So I suppose I need to do reconnect() and disconnect() before and after each transaction so that the db connection are returned to the pool promptly?
Or will it make sense if it's handled by Hibernate automatically each time beginTransaction() and commit()/rollback() are called?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 5:23 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, it's a bit more complex (and easier at the same time) than this. There is a page on the Wiki named "Session and Transaction scope". Read that first and then the relevant parts of the Hibernate documentation. If that doesn't help you and you still don't feel comfortable with Session, Transaction, and the JDBC connections, consider reading Hibernate in Action.

There is no "easy" answer to that, unless you are happy with "it depends".

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 5:56 pm 
Newbie

Joined: Wed May 12, 2004 2:57 pm
Posts: 17
I have read that, but I will read some more the rest of the documents.

Just to be clear. In a DB intensive app, is it best practice, in terms of performance, to use Open Session in View pattern and reconnect/disconnect before and after each transaction?

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 6:00 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, disconnect() and reconnect() is only usefull with long running Application Transactions which span several client request/response cycles.

The common pattern (without Application Transactions) is: One Session, one Transaction (which encapsulates the database transaction), one JDBC Connection, per client request. Thats a side-effect of the Open Session in View pattern.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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