-->
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: Hibernate - MySQL Problem. Connection gets closed in 8 hrs
PostPosted: Thu Sep 01, 2005 9:43 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Hi ,
I have a problem with Hibernate-MySQL appln in which database connection gets lost and is not recovering after some 5 hours of inactivity throwing, with following exception.


EXCEPTION
=========
Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.UnknownHostException
MESSAGE: serverURL

STACKTRACE:

java.net.UnknownHostException: serverURL
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:153)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:130)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:265)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1682)
at com.mysql.jdbc.Connection.<init>(Connection.java:400)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:224)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory


Any Idea why this happens only in Hibernate. I use same JDBC driver for other applications which work without causing this problem. Its only when used with Hibernate I get this error.

I saw few hints about this in MySQL forums, nothing worked for me. I will be grateful if anyone help me solve this.

Regards,
Aru K


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 4:03 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
This is because you use the default not for production connection pool that is enabled by default. Use C3P0 instead and your problem will be solved. If you're curious have a look at the source for the connection pool and from what I can remember it's just a simple infinity pool that doesn't validate stale/dead connections.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 4:38 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Hi Jamie,
Thanks for your reply.
Below is my configuration file which defines connection pool (using c3p0)

<hibernate-configuration>
<session-factory>
<!-- local connection properties -->

<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/rtttest
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>

<property name="hibernate.connection.username">arum</property>
<property name="hibernate.connection.password">priya</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">30</property>
<property name="hibernate.c3p0.max_statements">50</property>


<!-- dialect for MySQL -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping resource="cmmi.hbm.xml" />
</session-factory>
</hibernate-configuration>



Am I missing anything here? I do not get any exception when I use the application without any big break.

Your kind assistance is greatly appreciated.

Regards,
Aru K


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 5:08 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Code:
<property name="hibernate.connection.username">arum</property>
<property name="connection.password">priya</property>
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">30</property>
<property name="c3p0.max_statements">50</property>


Is the correct way of putting it in hibernate.cfg.xml

Note the lack of hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 5:21 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Hi ,
Even if I ignore hibernate prefix, it works without any problem. But dont know if this would solve the problem. Is there anyway to simulate the dead condition within 5 mins, instead of default 8 hours in MySQL???

Thanks in advance!!!


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.