-->
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: Hibernate Database Connection Status
PostPosted: Tue Jun 30, 2009 8:03 am 
Newbie

Joined: Tue Jun 30, 2009 7:53 am
Posts: 4
Hi,

I'am using Hibernate 3.1.3 for for database interaction. I'am using c3p0 for connection pool strategy. I have a problem whenever we stop the database, we get exception, HiberbateException when operating on session objects,
like say on session.createQuery() method.

When the database connection is lost, I wish to check the exception if it occurred because of disconnection from database and customize my response. If it is because of disconnection, I wish to reconnect to database. How to know the database connectivity status in Hibernate?

Thanks,
Sanjeev Srinath

_________________
Thanks,
Sanjeev Srinath


Top
 Profile  
 
 Post subject: Re: Hibernate Database Connection Status
PostPosted: Wed Jul 01, 2009 6:02 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
session.getconnection() gives you the Connection object, from this object you can get the status of connection


Top
 Profile  
 
 Post subject: Re: Hibernate Database Connection Status
PostPosted: Wed Jul 01, 2009 6:23 am 
Newbie

Joined: Tue Jun 30, 2009 7:53 am
Posts: 4
Hey thanks for the reply. I already tried by getting session.connection() method, and tried to check the status by using connection.isClosed(), but it once again throws exception. Even if I initialize Connection object before the exception as well, it is showing the status based on the status of whether this connection is closed by session it was invoked on. I do not want the status of connection based on the session object, I wish to know the status of database connectivity if it is still present between application and database.

Hope you understand my requirement.

Thanks,
Sanjeev Srinath

_________________
Thanks,
Sanjeev Srinath


Top
 Profile  
 
 Post subject: Re: Hibernate Database Connection Status
PostPosted: Wed Jul 01, 2009 7:56 am 
Newbie

Joined: Mon Mar 26, 2007 3:33 am
Posts: 18
When you r using c3p0 , c3p0 will take care of refreshing your connection. you need to add configuration for c3p0 which refresh the connection after certain interval.


Top
 Profile  
 
 Post subject: Re: Hibernate Database Connection Status
PostPosted: Wed Jul 01, 2009 8:16 am 
Newbie

Joined: Tue Jun 30, 2009 7:53 am
Posts: 4
Ranveer, when I get disconnected, as the session object will raise the exception, so can I know the reason that the exception is raised because of database disconnection(like the database connection is lost because of the command from administrator)?

_________________
Thanks,
Sanjeev Srinath


Top
 Profile  
 
 Post subject: Re: Hibernate Database Connection Status
PostPosted: Sun Jul 12, 2009 7:56 am 
Newbie

Joined: Mon Mar 26, 2007 3:33 am
Posts: 18
Hi Sanjeev,
I am not sure about Hibernate but if you check the log file c3p0 gives error about database connection status. Let me try?


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.