0 Replies Latest reply on Nov 21, 2014 4:56 AM by aqtwrdnr

    How to load an embedded h2 database dynamically from a singleton EJB.

    aqtwrdnr

      Hello,

       

      I would like to load an embedded h2 database dynamically from a singleton startup EJB. The location of the h2 database (lets say: ~/temp) is provided via a JNDI binding.

       

      I have it working in an unmanaged environment (i.e. POJO) and I have tried the same strategy in the EJB in JBoss 7.2.0.Final:

      1. Use Persistence.createEntityManagerFactory("persistenceH2", <map with hibernate.connection.url based on h2 database location provided via JNDI>) to create an EntityManagerFactory named emf
      2. Use emf.createEntityManager() to create an entity manager.
      3. Create an EAR with inside it the EJB jar with the singleton startup EJB. The EJB jar manifest file contains a dependency on module 'com.h2database.h2 export' module which seems to load successfully.

       

      However, this method fails when creating the EntityManagerFactory with a "java.sql.SQLException: No suitable driver found for jdbc:h2:~/temp". The full exception can be found in the attached dynamic-h2-database-load-jboss.log excerpt in which I have renamed company specific packages/classes by XXX.

       

      Despite the by JBoss provided h2database module on the classpath, it still cannot find a suitable driver. Any idea what else I can try or is there a better approach to dynamically load a h2 database from an EJB?

       

      Thanks in advance,

       

      Barry