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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate FAQ
PostPosted: Mon Jul 25, 2011 11:38 pm 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi All,

I have started this thread to know more about hibernate . I hope I will learn more here. Please clarify my queries.

1) In JDBC we use Connection class to communicate with database. We make use of DriverManager.
In hibernate we configure a datasource and we get a session object.

What is the difference between the Connection class and the Session class. Please let me know the similarities and differences.

2) We maintain a connection pool in hibernate configuration file / or a datasource file. We say a min-pool-size as 'X' and max-pool-size as 'Y'.

Consider X=5
and Y = 5.

What it means actually with respect to connections . In a transaction, we do open and close session objects in code. When we open a session, does it mean the min pool size reduces by X-1 ?? and when we close how many connections are available.

Please clarify.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Hibernate FAQ
PostPosted: Wed Jul 27, 2011 10:23 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
1) In JDBC we use Connection class to communicate with database. We make use of DriverManager.
In hibernate we configure a datasource and we get a session object.

What is the difference between the Connection class and the Session class. Please let me know the similarities and differences.

That's a big question, I'm going to be short as the complete answer would require me to re-write our documentation or books.
A Connection is basically just a handle to a "channel", commands you send are executed right away. A Session is stateful, it caches information that you might ask again (you get the same object reference if loading the same entities multiple times), and it "queues up" changes you want to apply to the database but postpones them in efficient batched prepared statements, possibly reordering them and merging several operations, to the flush or commit time.

Quote:
What it means actually with respect to connections . In a transaction, we do open and close session objects in code. When we open a session, does it mean the min pool size reduces by X-1 ?? and when we close how many connections are available.

Opening a Session doesn't open a Connection, but a Session might need to briefly open and release a connection for short times if it needs so. Generally it makes it possible to reuse connections in a more efficient form. Isolation levels and running are maintained.

_________________
Sanne
http://in.relation.to/


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