-->
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: about session,sessionfactory,jdbc conn
PostPosted: Tue Nov 15, 2005 1:35 pm 
Newbie

Joined: Fri Oct 28, 2005 10:32 pm
Posts: 13
hi,I am now confused about the relationship between session and sessionfactory,also the relationship between session and jdbc connection.

what does "session.close()" do ? does it close a jdbc connection?
what does "sessionfactory.openSession()" do?

when to close a hibernate session?

any reply would be much appreciated.thx in advance.


Top
 Profile  
 
 Post subject: Re: about session,sessionfactory,jdbc conn
PostPosted: Tue Nov 15, 2005 2:04 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
>what does "session.close()" do ? does it close a jdbc connection?

No, it does not close jdbc connection, it returns connection to the pool.
Session close() cleans H session cache.

>what does "sessionfactory.openSession()" do?

Creates Hibernate session which is a temporary cache for relevant persistent objects and the session works as operation buffer.

>when to close a hibernate session?
There are multiple strategies. My favorite is session-per-business-transaction
http://www.hibernate.org/42.html
http://www.hibernate.org/43.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Re: about session,sessionfactory,jdbc conn
PostPosted: Wed Nov 16, 2005 12:56 am 
Newbie

Joined: Fri Oct 28, 2005 10:32 pm
Posts: 13
kgignatyev wrote:
>what does "session.close()" do ? does it close a jdbc connection?

No, it does not close jdbc connection, it returns connection to the pool.
Session close() cleans H session cache.

>what does "sessionfactory.openSession()" do?

Creates Hibernate session which is a temporary cache for relevant persistent objects and the session works as operation buffer.

>when to close a hibernate session?
There are multiple strategies. My favorite is session-per-business-transaction
http://www.hibernate.org/42.html
http://www.hibernate.org/43.html


thank you for your reply.these words help me a lot.
according to http://www.hibernate.org/42.html
"
Transactions
Transactions also group data access operations, in fact, every SQL statement, be it queries or DML, has to execute inside a database transaction.
"
but I don't know why queries should be involved in a trasaction?
it has nothing to do with the status of the db.


Top
 Profile  
 
 Post subject: Re: about session,sessionfactory,jdbc conn
PostPosted: Wed Nov 16, 2005 1:55 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
do1doer wrote:
"
Transactions
Transactions also group data access operations, in fact, every SQL statement, be it queries or DML, has to execute inside a database transaction.
"
but I don't know why queries should be involved in a trasaction?
it has nothing to do with the status of the db.


Well, lets suppose we started to query a table and another process tries to change data in the same table.
Should we see changed data? What if the update transaction is unsuccessful?
To answer these and other questions in a predictable fashion we need transactions with well defined isolation levels: SERIALIZABLE, REPEATABLE_READ, etc.
http://www.postgresql.org/docs/7.4/inte ... n-iso.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Re: about session,sessionfactory,jdbc conn
PostPosted: Tue Dec 13, 2005 11:32 am 
Newbie

Joined: Fri Oct 28, 2005 10:32 pm
Posts: 13
Quote:
No, it does not close jdbc connection, it returns connection to the pool.
Session close() cleans H session cache.


I am using Mysql and proxool,and another problem emerges:
Mysql automatically closes an idle connection every certain minuntes.

consider this situation,
when hibernate closes a session,the db-connection is returned to
proxool pool,then after a certain time Mysql automatically closes
this db-connection.but the proxool seems not aware of this,it return
a closed connection to hibernate the next time I call "sessionFactory.openSession();" then "No operations allowed after connection closed" exceptions occur.

how to handle this?


Top
 Profile  
 
 Post subject: try
PostPosted: Tue Dec 13, 2005 1:44 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
You may try autoreconnect connection parameter for MySQL JDBC
jdbc:mysql://zzzz:3306/foo?autoReconnect=true

or specify proxool.house-keeping-test-sql parameter for proxool

http://proxool.sourceforge.net/configure.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.