Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 410055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:51:03+00:00 2026-05-12T17:51:03+00:00

I have an application that uses Hibernate to connect to my MySQL database. I’m

  • 0

I have an application that uses Hibernate to connect to my MySQL database. I’m just having a weird problem with timeouts. Let’s say that the socket timeout in MySQL’s configurations is set to one hour. After an hour of inactivity, the socket times out as expected. The problem is that Hibernate doesn’t seem to be able to handle the socket timeout, because when Hibernate tries to make a database query, a SocketException is thrown. Instead of handling the exception internally, hibernate just “dies” and cannot recover from the exception in any other way than for me to manually build a new SessionFactory.

The question is, how can I avoid this problem so that I do not have to manually keep track of timeouts?

EDIT
Your suggestions seem to be the right way to go, but for some reason I’m not able to get it to work. I tried following the instructions on http://www.michaelstudman.com/fullfathomfive/articles/2004/06/07/mysql-dropping-connections-and-hibernate and the instructions on the page Jimmy linked to, but I’m still getting the same exception and my application fails due to it. Might it have something to do that I’ve set mysql’s timeout to 120 seconds (for testing purposes only), but I changed the c3p0 timeout to 100 seconds.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:51:04+00:00Added an answer on May 12, 2026 at 5:51 pm

    The best way to handle these types of issue is to configure you connection pool to validate the connection before it is handed out to the application (be it hibernate or what ever).

    Most connection pools allow you to configure a simple query some thing like SELECT 1=1 for mysql or SELECT 1 FROM DUAL in oracle. If you are using commons dbcp then the configuration name is validateQuery and testOnBorrow.

    I’ve actually answered a similar question…relating to the flip side of this issue and that’s too much validation of connections!

    SELECT 1 from DUAL: MySQL

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that uses Hibernate's 2nd level caching to avoid database hits.
I have an application that uses hibernate and JPA to handle the database. I
We have an application that uses NHibernate to connect to our database on SQL
I have a struts application that uses Hibernate to access a MYSQL DB. I
I have a Java application (generic) that uses a database via hibernate. I ship
I have just started working on an existing Wicket application that uses Hibernate. I
I have an application that uses Hibernate. It generated the following SQL statement. I
I have an application that uses Hibernate for its domain objects. One part of
I have a client application that connects to a server. The server uses hibernate
I have a JPA/Spring application that uses Hibernate as the JPA provider. In one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.