1

I'm having a problem with my one of my session beans and it may be because of my lack of understanding of EntityManagers. I'm using JBoss EAP 6.2 and Oracle.

I have an object (call it Maintainer) annotated as with @Singleton and @Startup. When instantiated, a @Stateless session bean (Repository) is injected into it, which itself is inject with an EntityManager.

@Singleton
@Startup         @Stateless       @PersistenceContext()
Maintainer ----> Repository ----> EntityManager

In the Maintainer's @PostConstruct method, it creates a thread that runs periodically to fetch objects from the database using the Repository. This thread lives for the life of the application. The code to retrieve the objects uses a native query that looks like this:

    Query query = entityManager.createNativeQuery(SQL_QUERY_ALL);
    query.setParameter(DATE_PARAM_NAME, sinceLastUpdateDate);
    List<Object[]> resultList = query.getResultList();

The problem I'm having is that when the application loses connection to the database, the thread starts throwing "java.sql.SQLRecoverableException: Closed Connection" exception. It does not reconnect, even after the database is brought back up and I have to shutdown and restart my application.

I'm sure that connection recovery is built into the underlying library so I'm guessing the problem is with my code and my understanding (or lack there-of) of how the EntityManager manages its connection to the database.

Can any clear me up on this. What's wrong with what I'm doing?

Thanks.

DaveR
  • 1,295
  • 1
  • 13
  • 35
  • Take a look http://stackoverflow.com/questions/128527/is-there-any-way-to-have-the-jboss-connection-pool-reconnect-to-oracle-when-conn – Federico Sierra Oct 28 '15 at 20:36

1 Answers1

0

Maybe its too late but for the record, you can add validation-on-match on the datasource like this:

  <validation>
     <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
     <validate-on-match>true</validate-on-match>
  </validation>
Milad
  • 89
  • 1
  • 8