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.  [ 5 posts ] 
Author Message
 Post subject: java.net.UnknownHostException hibernate retries endlessly
PostPosted: Sat Jul 11, 2009 8:38 pm 
Newbie

Joined: Sat Jul 11, 2009 8:30 pm
Posts: 3
When defining databases for hibernate to connect to, I have stumbled upon a problem that is now affecting our server when the database cannot accept any more connections.

If the hibernate.connection.url is incorrect, i can visibly see the error:

SEVERE: The connection to the host ________, named instance sql2008 has failed. Error: "java.net.UnknownHostException: _______". Verify the server and instance names, check that no firewall is blocking UDP traffic to port ____, and for SQL Server 2005 or later verify that the SQL Server Browser Service is running on the host.

The thread that is running the application stays open and continues trying to connect endlessly. I write applications using eclipse, and can visibly see this connection error over and over and over as hibernate sits and repeats the connection attempt.

Is there some setting i can use to tell hibernate to only try to connect a certain number of times and then throw an error? I simply cannot have a production server that gets thread-locked due to threads that are endlessly attempting to connect to the database.

Any help is greatly appreciated.


Top
 Profile  
 
 Post subject: Re: java.net.UnknownHostException hibernate retries endlessly
PostPosted: Sat Jul 11, 2009 11:25 pm 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Please let us know the Hibernate Core version and your, hibernate.cfg.xml and which connection pooling mechanism you are using.


Top
 Profile  
 
 Post subject: Re: java.net.UnknownHostException hibernate retries endlessly
PostPosted: Mon Jul 13, 2009 10:28 am 
Newbie

Joined: Sat Jul 11, 2009 8:30 pm
Posts: 3
Although I am not the one that originally configured hibernate for this project, I believe I have located the xml that would normally be found inside of hibernate.cfg.xml.

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://*****;databaseName=******</property>
<property name="hibernate.connection.username">*****</property>
<property name="hibernate.connection.password">******</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<mapping resource="DataType/DataTypeUBigInt.hbm.xml"/>
<mapping resource="DataType/DataTypeUUID.hbm.xml"/>
...
</session-factory>
</hibernate-configuration>

As far as connection pooling goes, I don't believe any has been implemented. The jar we are using for hibernate is named hibernate3.jar, though I don't know the exact version. Thanks for responding, and I hope this information is enough to help diagnose my problem.


Top
 Profile  
 
 Post subject: Re: java.net.UnknownHostException hibernate retries endlessly
PostPosted: Tue Jul 14, 2009 12:09 pm 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
I think you should use some connection polling mechanism like C3P0.

As per the configuration file (What you post), your code will use
Quote:
DriverManagerConnectionProvider
class (it is inside the hibernate3.jar in org.hibernate.connection package) for providing the connection. This class just provide basic connection pooling , but doesn't deal with more sophisticated issues like you mention.

My suggestion is use some connection pooling provider and integrate it with hibernate. and you can configure that connection pool as you want (like allow only 3 attempt to connection to database to get connection).

Another way is you implement
Quote:
ConnectionProvider
interface (it is hibernate's interface) which should have logic to provide the connection to hibernate as well have logic to number of retry.


Top
 Profile  
 
 Post subject: Re: java.net.UnknownHostException hibernate retries endlessly
PostPosted: Tue Jul 14, 2009 1:33 pm 
Newbie

Joined: Sat Jul 11, 2009 8:30 pm
Posts: 3
Thank you for your reply. I have been leaning toward implementing c3p0 for a few days now, and your response pretty much confirms my suspicions.

I appreciate your help.


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