title: How to re-establish the connection after network failure in JBoss AS 7.x -JPA
body: <p>My application is using JPA(Hbernate ORM)  to connect to the SQL server 2008 , Which was deployed in JBoss AS 7.x server. If the network goes down and came up again , i am getting the following exception</p>
  
  <pre><code>14:59:27,996 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: The connection is closed.
  14:59:28,002 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361)
  14:59:28,012 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)
  14:59:28,020 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:261)
  14:59:28,025 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at com.honeywell.domoweb.dataservice.dao.impl.UserDaoImpl.getUsers(UserDaoImpl.java:372)
  14:59:28,030 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  14:59:28,034 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  14:59:28,039 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  14:59:28,044 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at java.lang.reflect.Method.invoke(Method.java:597)
  14:59:28,047 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
  14:59:28,052 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
  14:59:28,058 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
  14:59:28,064 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
  14:59:28,069 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  14:59:28,075 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
  14:59:28,080 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at $Proxy66.getUsers(Unknown Source)
  14:59:28,083 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at com.honeywell.domoweb.dataservice.dao.impl.TemplateDaoImpl.getTemplate(TemplateDaoImpl.java:44)
  14:59:28,089 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...
  </code></pre>
  
  <p>I googled out this issue and found that this issue needs a change in the connection pool configuration to reconnect again using autoReconnect attribute ,but didn't found any example ,how to embed the autoReconnect with my Connection pool settings.Below is my Connection pool settings in the Standalone.xml file</p>
  
  <pre><code>&lt;subsystem xmlns="urn:jboss:domain:datasources:1.0"&gt;
          &lt;datasources&gt;
  
  
              &lt;datasource jndi-name="java:jboss/datasources/DataServiceDS" pool-name="dataServicePool" enabled="true" use-java-context="true"&gt;
                  &lt;connection-url&gt;jdbc:sqlserver://ipaddress:1433;databaseName=myDataBase&lt;/connection-url&gt;
                  &lt;driver&gt;sqlserver&lt;/driver&gt;
                  &lt;pool&gt;
                      &lt;min-pool-size&gt;10&lt;/min-pool-size&gt;
                      &lt;max-pool-size&gt;100&lt;/max-pool-size&gt;
                      &lt;prefill&gt;true&lt;/prefill&gt;
                  &lt;/pool&gt;
                  &lt;security&gt;
                      &lt;user-name&gt;usename&lt;/user-name&gt;
                      &lt;password&gt;password&lt;/password&gt;
                  &lt;/security&gt;
              &lt;/datasource&gt;
              &lt;drivers&gt;
  
                  &lt;driver name="sqlserver" module="com.microsoft.sqlserver"&gt;
                      &lt;xa-datasource-class&gt;com.microsoft.sqlserver.jdbc.SQLServerDriver&lt;/xa-datasource-class&gt;
                  &lt;/driver&gt;
              &lt;/drivers&gt;
          &lt;/datasources&gt;
      &lt;/subsystem&gt;
  </code></pre>
  
  <p>Can you please let me know ,how to re-connect to the database , if Network goes down and reconnected again ? </p>