-->
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: Help Regarding disconnecting a Connection from session
PostPosted: Sat Mar 21, 2009 10:19 am 
Newbie

Joined: Tue Mar 17, 2009 2:34 am
Posts: 4
Location: Chennai
Hibernate version:3.1

Am using session-per-conversation pattern using Servlet filters. Am currently using some hibernate previous releases disconnect and reconnect functions. Since these functions are deprecated in 3.1 they have no effect. I read that in 3.1 connections will be disconnected automatically after commit. But when am calling session.isConnected() after session.commit, still it returns true only. Am new to hibernate. Please help with a way to disconnect
a connection from the session.

I used the following code for testing disconnection in Hibernate 3.1

session=HibernateUtil.getSessionFactory().openSession();
Transaction t = session.beginTransaction();
-----------------
-----------------
t.commit();
System.out.println(session.isConnected());


and


session=HibernateUtil.getSessionFactory().openSession();
Transaction t = session.beginTransaction();
-----------------
-----------------
t.commit();
session.disconnect();
System.out.println(session.isConnected());



Both of them returns true only.. Sorry if my doubt is silly..
Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 2:51 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
I think you are getting Session and Transaction confused.

The transaction is a wrapper around the commands you are giving to the database.
Code:
A transaction is associated with a Session and is usually instantiated by a call to Session.beginTransaction(). A single session might span multiple transactions since the notion of a session (a conversation between the application and the datastore) is of coarser granularity than the notion of a transaction. However, it is intended that there be at most one uncommitted Transaction associated with a particular Session at any time.

http://www.hibernate.org/hib_docs/v3/ap ... ction.html

And a session
http://www.hibernate.org/hib_docs/v3/ap ... ssion.html

committing a transaction does not close a database connection, it just forces all your changes to be persisted.

session.close() will close your database connection. I believe this is the best practice as I haven't seen a newer example that uses session.disconnect. This is just my opinion though maybe this will help.

http://forum.hibernate.org/viewtopic.php?t=924565

Most of the newer examples only show session.close()
http://www.hibernate.org/42.html

Hope this helps.

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject: Using Session-per-Conversation
PostPosted: Tue Mar 24, 2009 12:10 am 
Newbie

Joined: Tue Mar 17, 2009 2:34 am
Posts: 4
Location: Chennai
Thanks ethnarch for ur rply.

I want to use session-per-conversation pattern in my application( i.e., Same session should be reused for more than one HTTP requests and for each request JDBC connection will be established and at the end of the request, the connection will be disconnected). For that, I need to disconnect a JDBC connection during user think time and reconnect whenever needed with a single hibernate session. It is possible in older versions(3.0-am checked) of hibernate using disconnect and reconnect methods. But am not able to do that in hibernate 3.2.5ga. Please guide me in doing this.

Session-per-Conversation pattern detail : http://www.hibernate.org/42.html


Top
 Profile  
 
 Post subject: Using Session-per-Conversation
PostPosted: Tue Mar 24, 2009 12:15 am 
Newbie

Joined: Tue Mar 17, 2009 2:34 am
Posts: 4
Location: Chennai
Thanks ethnarch for ur rply.

I want to use session-per-conversation pattern in my application( i.e., Same session should be reused for more than one HTTP requests and for each request JDBC connection will be established and at the end of the request, the connection will be disconnected). For that, I need to disconnect a JDBC connection during user think time and reconnect whenever needed with a single hibernate session. It is possible in older versions(3.0-am checked) of hibernate using disconnect and reconnect methods. But am not able to do that in hibernate 3.2.5ga. Please guide me in doing this.

Session-per-Conversation pattern detail : http://www.hibernate.org/42.html


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.