GlassFish Server部署和MySQLNonTransientConnectionException

时间:2013-05-20 13:18:47

标签: java jpa eclipselink glassfish-3 web-deployment

当我部署我的应用程序时,一段时间后我得到了这个例外:

    javax.servlet.ServletException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

我正在使用持久性单元,具有以下设置:

    <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="PU" transaction-type="JTA">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>myconnhere</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>NONE</shared-cache-mode>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
     <property name="autoReconnect" value="true"/>
    </properties>
  </persistence-unit>
</persistence>

如何避免/解决此问题?这是java问题还是MySQL配置?

我在JPA.xml中添加了<property name="autoReconnect" value="true"/> - 正如我在SO上找到的那样。但是,这并不能解决问题。 我还删除了GlassFish(3.1.2)管理中的连接池超时(设置为0)。

1 个答案:

答案 0 :(得分:0)

这是一个驱动程序参数,因此您必须修改GlassFish连接池中的URL。在管理员界面中:资源 - &gt; JDBC - &gt; JDBC连接池 - &gt;你的游泳池 - &gt;附加属性。

另一个选项是在“高级”选项卡中启用“连接验证”。