Hibernate automatically reconnect to database __ database

Source: Internet
Author: User

This is where the Tomcat application (persistence layer is hibernate) and the database are on different machines, and the connection breaks down when the database restarts or problems or the network is faulty. You will need to restart Tomcat after the repair, otherwise the application will continue to report connection refused errors. What is the way to get hibernate to automatically reconnect to the database after knowing that the connection failed?

Search on the Internet a lot of information is not a good solution, and finally replaced the connection pool, the use of Proxool

Specific configuration can see an article "Hibernate configuration Proxool" http://blog.csdn.net/cgboy88/archive/2010/05/10/5574839.aspx

One of the most important parameter settings is

Test-before-use: If True, the connection is serviced before each connection is tested, if one connection fails, it is discarded, another connection is processed, and if all connections fail, a new connection is established. Otherwise, a SqlException exception will be thrown.

Test-after-use: If True, the connection is serviced after each connection is tested and returned to the connection pool, which is discarded if the connection fails.

Test-before-use: and Test-after-use: I only chose one and tested the network to pass when disconnected.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.