2 Replies Latest reply on Sep 3, 2013 7:20 AM by roberto.schneiders

    How do I configure a Derby Embedded database (in memory) with JBoss / JPA?

    roberto.schneiders

      I'm trying to use an embedded database (in memory) in a JavaEE application (with JPA/Hibernate) on JBoss AS 7.1.1.Final.

       

      My goal is to simplify as much as possible to deploy this application. I do not want to have to deploy derby separately or configure datasources in JBoss console. I want to deploy the EAR, and only that.

      The idea of using an embedded database is just to simplify their use and eliminate the need for additional settings that will generate higher maintenance costs at the deployment time.

       

      I've tried many things but so far nothing has worked. I posted a question on SO but got no answer. (http://stackoverflow.com/questions/18410865/how-to-set-environment-with-derby-embedded-jpa-2-0-hibernate-in-a-javaee-app)

       

      First I added the Derby dependencies to my war maven config.

          <dependency>
               <groupId>org.apache.derby</groupId>
               <artifactId>derby</artifactId>
               <version>10.10.1.1</version>
          </dependency>
      
      
      

      That way, I have the file "derby-10.10.1.1.jar" in that directory: deployments\MyEAR.ear\MyWar.war\WEB-INF\lib

      I suppose that's enough for the Derby Embedded drivers are available.

       

      My persistence.xml looks like this:

      <persistence 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"
        version="2.0">
      
        <persistence-unit name="TributarioEmbarcado" transaction-type="RESOURCE_LOCAL">
             <class>com.sysmo.client.tributario.baseEmbarcada.model.LoginEmbarcado</class>
             <class>com.sysmo.client.tributario.baseEmbarcada.model.ConfiguracaoEmbarcado</class>
      
             <properties>
                 <property name="hibernate.connection.autoReconnect" value="true" />
                 <property name="hibernate.connection.autoReconnectForPools" value="true" />
                 <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
                 <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver" />
                 <property name="hibernate.connection.url"  value="jdbc:derby:memory:sysmo_tributario_embarcado;create=true" />
             </properties>
        </persistence-unit>
      </persistence>
      
      
      

       

      This is the Entity manager factory code.

      EntityManagerFactory factory = Persistence.createEntityManagerFactory("TributarioEmbarcado");
      em = factory.createEntityManager();
      
      
      

       

      I'm experiencing this problem:

      ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (MSC service thread 1-1) No suitable driver found for jdbc:derby:sysmo_tributario_embarcado;create=true

       

      The error occurs on the second line of this code:

      Query query = em.createQuery("from ConfiguracaoEmbarcado");
      configuracaoEmbarcado = (ConfiguracaoEmbarcado) query.getSingleResult();
      

       

      Even if I deploy the "derby-10.10.1.1.jar" from the console of JBoss, this error occurs.

      What am I doing wrong?