Hi All.
I'm trying to solve very basic problem for a few days and now getting a real headache.
How to configure Toplink to reestablish DB connection once it's broken (for ex. DB server restarted)?
I'm using Toplink in SE mode with Tomcat and MySQL. If I restart MySQL, the web application becomes non-operational with Toplink exception:
------------------------
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
. . .
... 36 more
Caused by: java.net.SocketException: Broken pipe
------------------------
I considered the following options:
1. Configuring Toplink's internal connection pool to reestablish connections -- there are no appropriate configuration options.
2. Registering SessionCustomizer with exception handler similar to
http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/sescfg007.htm -- but reestablishing connection didn't work and produced a MySQL exception.
3. Using autoReconnect connection property of MySQL -- but MySQL folks do not recommend it (
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html) .
4. Using Tomcat's JNDI DataSource as in
http://javanotepad.blogspot.com/2007/07/working-with-non-jta-datasource-in.html -- but my application is modular and I can not hardcode <non-jta-data-source> in persistence.xml. Currently connection parameters are defined in <properties> of persistence.xml and I can override those passing a Map to Persistence.createEntityManagerFactory().
How to solve this problem? Any help is really appreciated.
Thanks
[Message sent by forum member 'sultanbek' (sultanbek)]
http://forums.java.net/jive/thread.jspa?messageID=268206