15

I have successfully made a connection to a remote MySQL server through Glassfish, however each time I make a change to the code or XHTML files, I need to open the administrator panel of Glassfish and flush the connection pool, otherwise I get the following error when I just refresh the page. Has anybody experienced this? I can post code or other information if it is needed.

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: WELD-000049 Unable to invoke [method] @PostConstruct public com.myapp.QuestionController.initialize() on com.myapp.QuestionController@4635bd2a

root cause

org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke [method] @PostConstruct public com.myapp.interfaces.QuestionController.initialize() on com.myapp.interfaces.QuestionController@4635bd2a

root cause

java.lang.reflect.InvocationTargetException

root cause

javax.ejb.EJBException

root cause

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: java.lang.RuntimeException: Got exception during XAResource.start: Error Code: 0

root cause

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: java.lang.RuntimeException: Got exception during XAResource.start: Error Code: 0

root cause

java.sql.SQLException: Error in allocating a connection. Cause: java.lang.RuntimeException: Got exception during XAResource.start:

root cause

javax.resource.spi.ResourceAllocationException: Error in allocating a connection. Cause: java.lang.RuntimeException: Got exception during XAResource.start:

root cause

com.sun.appserv.connectors.internal.api.PoolingException: java.lang.RuntimeException: Got exception during XAResource.start:

root cause

com.sun.appserv.connectors.internal.api.PoolingException: java.lang.RuntimeException: Got exception during XAResource.start:

root cause

java.lang.RuntimeException: Got exception during XAResource.start:

root cause

javax.transaction.xa.XAException: com.sun.appserv.connectors.internal.api.PoolingException: javax.resource.spi.LocalTransactionException: Communications link failure

The last packet successfully received from the server was 435�409 milliseconds ago. The last packet sent successfully to the server was 7 milliseconds ago.

Image of config

Persistence XML

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="SertifikatPU" transaction-type="JTA">
        <jta-data-source>jdbc/sertifikatdb</jta-data-source>
    </persistence-unit>
</persistence>

In the "Additional properties" in Glassfish connection pool settings I have just configured: servername, URL, user and password.


I HAVE SOLVED THIS PROBLEM

enter image description here

I made my own dual table, similar to the one in Oracle.

CREATE TABLE dual 
(
    x VARCHAR(1)
);

INSERT INTO dual(x) VALUES('y');
JoshDM
  • 4,939
  • 7
  • 43
  • 72
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
  • Non Transactional Connections, Transaction Isolation:, Isolation Level: --> These are grouped under Transactions, any of them? – LuckyLuke Oct 18 '11 at 20:27
  • How are you obtaining the connection? That may cause this exception. Also what is the connection pool configuration. – r0ast3d Oct 20 '11 at 20:01
  • Is there a reference to the connection being held somewhere? Could you pls add more info... Also on the remote server, what is the configuration for the number of clients and connections? – r0ast3d Oct 20 '11 at 20:18
  • @r0ast3d Added image link at bottom – LuckyLuke Oct 20 '11 at 20:19
  • @BPDeveloper The idle time looks small, considering that you are connecting to a remote box and also considering that you mentioned that this issue comes during development and between restarts. However I am still pinning on how the connection is obtained in the first place. – r0ast3d Oct 20 '11 at 22:00
  • @BPDeveloper could you post a snippet of how you are obtaining the connection? Also does increasing the idle time help your timeouts? – r0ast3d Oct 21 '11 at 15:21
  • @r0ast3d I updated with more information – LuckyLuke Oct 21 '11 at 17:14

2 Answers2

20

Your root cause, PoolingException: javax.resource.spi.LocalTransactionException: Communications link failure is related to this Glassfish bug, which explains (in the comments tab at the bottom) that you may need to refresh your invalid connections.

The bug comment by Jagadish says to check your connection validation type. If it is set to "autocommit" (the default), the JDBC drivers may cache the prior connection validation data, and no actual database interaction will happen during future connection validations.

To resolve the problem, set connection-validation-method="table" and validation-table-name="any_table_you_know_exists" (replace any_table_you_know_exists with the name of any existing table). Doing this forces the connections to talk to the database instead of the cache; if the connection is invalid, it will be dropped and recreated. You may need to also specify is-connection-validation-required="true".

Articles to help with additional configuration:

  1. This article also explains the problem in detail.
  2. Jagadish's Oracle Blog Article on this topic has more info.
  3. Article explaining Glassfish JDBC Connection Validation in detail.

Text from Jagadish's blog:

AS_INSTALL_ROOT/bin/asadmin set domain.resources.jdbc-connection-pool.DerbyPool.is-connection-validation-required=true
domain.resources.jdbc-connection-pool.DerbyPool.is-connection-validation-required = true

AS_INSTALL_ROOT/bin/asadmin set domain.resources.jdbc-connection-pool.DerbyPool.connection-validation-method=table
domain.resources.jdbc-connection-pool.DerbyPool.connection-validation-method = table

bin/asadmin set domain.resources.jdbc-connection-pool.DerbyPool.validation-table-name=sys.systables
domain.resources.jdbc-connection-pool.DerbyPool.validation-table-name = sys.systables

Note that the sample code refers to sys.systables, which is a MS SQL table that is guaranteed to exist. For Oracle, refer to the guaranteed table dual. For MySQL, create a 1-column table solely for validation purposes; play it safe and pre-populate the table by inserting one row of data.

kaartic
  • 523
  • 6
  • 24
JoshDM
  • 4,939
  • 7
  • 43
  • 72
  • Thank you for your response. I am new to this so I could need just a little help to where to configure this. I went to localhost:4848-->JDBC connection pools --> selected my connection-->then advanced tab. I found the connection-validation-method you were talking about and also selected the connection-validation-required. But I do not see the validation-table-name. – LuckyLuke Oct 21 '11 at 07:09
  • Also, see [this article](http://blogs.oracle.com/JagadishPrasath/entry/connection_validation_in_glassfish_jdbc) ASAP. Apparently' it's also written by the same Jagadish I mention earlier (his blog!) and suggests using `fail-all-connections` to refresh on failure. [Here](http://alexandru-ersenie.com/2011/03/01/glassfish-jdbc-connection-validation-explained/) is a second article which explains glassfish JDBC Connection Validation in detail. Both are excellent reads! – JoshDM Oct 21 '11 at 17:31
  • In your `domain.xml` what does your connection pool xml code look like? I believe that is where you set the properties I've suggested. – JoshDM Oct 22 '11 at 02:02
  • 1
    Thank you! It solved my problems. I did not have the oppertunity to check this out before because the host had some problems :=) – LuckyLuke Oct 22 '11 at 09:58
1

Should you be using this driver?

com.mysql.jdbc.jdbc2.optional.MysqlXADataSource 

I see that you are using a different driver from the attached image ...

r0ast3d
  • 2,639
  • 1
  • 14
  • 18