Why do I need to flush the connection pool each time I redeploy?

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 ...


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.