-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to check if the database is available?
PostPosted: Fri Mar 16, 2007 8:36 am 
Newbie

Joined: Fri Mar 09, 2007 10:12 am
Posts: 6
Hi all,

Sorry but I'm probably blind. I want to disable the use of Hibernate in my application if it will "probably" not work properly p.e. no connection to the database can be created.

I could use JDBC in order to test the connection to the database. However, the parameters of the connection are in hibernate.cfg.xml. So I guess Hibernate should be able to return the connection state. If I shutdown my database engine, the SessionFactory get still initialized (buildSessionFactory() does not throw any exception). I have tried to open a session with openSession(). Still no exception. However, I get lots of exceptions from C3P0 in the logs.

So, how to check if the database is available?

I'm using C3P0 with a MySQL database.

Thank you

P.S. I just think about the "hbm2ddl.auto" property. I will test this now but maybe there are other solutions.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 9:48 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
You can use buildSettings().getConnectionProvider() from your Configuration object before you use buildSessionFactory.
Then you can play with the connection provider to see if you can connect to the database

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 10:16 am 
Newbie

Joined: Fri Mar 09, 2007 10:12 am
Posts: 6
Thank you :-) This is exactly what I was looking for.


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