Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Hibernate timeout on connection
Hibernate timeout on connection [message #1004193] Tue, 22 January 2013 19:16 Go to next message
Rafael Fogel is currently offline Rafael FogelFriend
Messages: 21
Registered: January 2013
Junior Member
I have a small app that connects on multiple hosts, but sometimes those hosts are down or I can't access by some reasons.


I am connecting like this:

serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();

sessionFactory = configuration.buildSessionFactory(serviceRegistry);

Hibernate keeps trying to connect forever on unreachable host. Is there a way to set a timeout on hibernate connection?
Re: Hibernate timeout on connection [message #1004243 is a reply to message #1004193] Tue, 22 January 2013 21:25 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rafael,
Hmm, I would need to do a google search to reply on this question, I guess it is possible to set a connection timeout,
maybe you have autoReconnect set somehow (this is possible with mysql it seems).

Let me know if you find any specific solutions when searching the net. It would be great if you can post any solutions here.

gr. Martin

On 01/22/2013 08:16 PM, Rafael Fogel wrote:
> I have a small app that connects on multiple hosts, but sometimes those hosts are down or I can't access by some reasons.
>
> I am connecting like this:
>
> serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
>
> sessionFactory = configuration.buildSessionFactory(serviceRegistry);
>
> Hibernate keeps trying to connect forever on unreachable host. Is there a way to set a timeout on hibernate connection?


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: Hibernate timeout on connection [message #1005140 is a reply to message #1004193] Thu, 24 January 2013 14:49 Go to previous messageGo to next message
Rafael Fogel is currently offline Rafael FogelFriend
Messages: 21
Registered: January 2013
Junior Member
Thanks for replaying Martin. I searched but couldn't find anything.
Re: Hibernate timeout on connection [message #1005435 is a reply to message #1005140] Fri, 25 January 2013 12:38 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rafael,
Are you using a connection pool mechanism (c3p?)? Which database are you on?

gr. Martin

On 01/24/2013 03:49 PM, Rafael Fogel wrote:
> Thanks for replaying Martin. I searched but couldn't find anything.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: Hibernate timeout on connection [message #1005729 is a reply to message #1005435] Mon, 28 January 2013 12:47 Go to previous messageGo to next message
Rafael Fogel is currently offline Rafael FogelFriend
Messages: 21
Registered: January 2013
Junior Member
Yes, I am using c3p0, connectinng on MySQl

Here's my hibernate configuration:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">****</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/flexadmin</property>
<property name="hibernate.connection.username">***</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.auto">true</property>
<property name="hibernate.connection.autoReconnect">true</property>

<property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>

<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.preferredTestQuery">SELECT 1;</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.c3p0.idle_test_period">100</property>

</session-factory>
</hibernate-configuration>

As far as I know, c3p0 timeout refers to the connection's lifetime, not the attempt to connect.
Re: Hibernate timeout on connection [message #1005753 is a reply to message #1005729] Mon, 28 January 2013 14:53 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Have you tried without the autoReconnect option?

In your first post, when say tries to reconnect forever. It means that hibernate tries many times to create a
connection? Or that one connection hangs indefinitely?

gr. Martin

On 01/28/2013 01:47 PM, Rafael Fogel wrote:
> Yes, I am using c3p0, connectinng on MySQl
>
> Here's my hibernate configuration:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-configuration PUBLIC
> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
> <hibernate-configuration>
> <session-factory>
> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
> <property name="hibernate.connection.password">****</property>
> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/flexadmin</property>
> <property name="hibernate.connection.username">***</property>
> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
> <property name="hibernate.show_sql">true</property>
> <property name="hibernate.auto">true</property>
> <property name="hibernate.connection.autoReconnect">true</property> <property
> name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
> <property name="hibernate.c3p0.acquire_increment">1</property>
> <property name="hibernate.c3p0.validate">true</property>
> <property name="hibernate.c3p0.min_size">5</property>
> <property name="hibernate.c3p0.max_size">100</property>
> <property name="hibernate.c3p0.timeout">1800</property>
> <property name="hibernate.c3p0.max_statements">50</property>
> <property name="hibernate.c3p0.preferredTestQuery">SELECT 1;</property>
> <property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
> <property name="hibernate.c3p0.idle_test_period">100</property>
> </session-factory>
> </hibernate-configuration>
>
> As far as I know, c3p0 timeout refers to the connection's lifetime, not the attempt to connect.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: Hibernate timeout on connection [message #1005805 is a reply to message #1005753] Mon, 28 January 2013 19:40 Go to previous messageGo to next message
Rafael Fogel is currently offline Rafael FogelFriend
Messages: 21
Registered: January 2013
Junior Member
I tried with autoReconnect option false and got the same result.

How can I see if it's trying to make severel connections or just a eternal one?
Re: Hibernate timeout on connection [message #1005810 is a reply to message #1005805] Mon, 28 January 2013 19:52 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rafael,
Debug in the hibernate code? I mean, when running in eclipse you can pause all threads and check where they are...

Have you asked this on the hibernate forum? They don't always answer but maybe.

gr. Martin

On 01/28/2013 08:40 PM, Rafael Fogel wrote:
> I tried with autoReconnect option false and got the same result.
>
> How can I see if it's trying to make severel connections or just a eternal one?


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: Hibernate timeout on connection [message #1008003 is a reply to message #1005810] Fri, 08 February 2013 14:59 Go to previous message
Rafael Fogel is currently offline Rafael FogelFriend
Messages: 21
Registered: January 2013
Junior Member
Hello Martin, sorry for the delay.

Hibernate was making a eternal attempt to connect indeed. I found a solution on c3p0, using the propertie "checkoutTimeout" and "acquireRetryAttempts". With these, i now can set a timeout on connection.

Thanks for the help anyway.
Previous Topic:[CDO] Offline clone doesn't reload offline branche
Next Topic:EMF-to-XSD Model Transformation
Goto Forum:
  


Current Time: Fri Mar 29 14:11:35 GMT 2024

Powered by FUDForum. Page generated in 0.02810 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top