4 Replies Latest reply on Nov 23, 2016 12:45 PM by seto

    Wildfly not reading correct database

    erik777

      I have an existing database with data in tables.  But, Wildfly appears to be creating an in-memory database instead.  I cannot get it to connect to and use the correct database.

       

      1. I copied the persistence.xml from a jar that uses it without a problem via a Java standalone app.  That's where all the data came from.  In fact, even if I invoke this code from Wildfly via REST it works just fine, but is not using any container services.  I'm now using EJBs, so need for it to have it's own managed persistence unit.

       

      2. I inject with:

       

      @PersistenceContext(unitName="localWeb")

          private EntityManager em;

       

      3.  I have it updating the schema using hibernate.hbm2ddl.auto="update".  If I remove this line, then Wildfly complains that it cannot find the table when I run a query.  So, clearly, it is using the correct persistence unit from the WAR, which has a unique name.  The fact that it complains after previous runs suggests this is an in-memory database, and not a persisted one.  If it was persisted, then the tables would still exist from the last run.

       

      4. When I query the table for count, I get 0 entries, even though it has lots of data.  True whether or not I select count or select all entities and check size().  This is also indicative of it creating an empty in-memory database.  Sample code:

       

      List<ChartBar> list = em.createQuery("SELECT cb FROM ChartBar cb").getResultList();
      //Long cnt = em.createQuery("Select count(cb.key.symbol) from ChartBar cb", Long.class).getSingleResult();
      sb.append("Records in ChartBar: " + list.size());

       

      5. I tried installing the mysql connector per these instructions.  It reported success.  It made no difference.

       

      6. I tried changing from mariadb to mysql in the persistence.xml in the url and driver.  It made no difference.

       

      Here is the persistence.xml, with edits to preserve privacy:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence version="2.1"

          xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

          <persistence-unit name="localWeb">

              <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

              <class>net.openstandards.data.HeartBeat</class>

              <class>net.openstandards.data.ChartBar</class>

              <class>net.openstandards.data.StringStoreValue</class>

              

              <properties>

                  <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/blah" />

                  <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />

                  <property name="javax.persistence.jdbc.user" value="blah" />

                  <property name="javax.persistence.jdbc.password" value="blah" />

                 

                  <property name="jboss.as.jpa.managed" value="true" />

                  <property name="wildfly.jpa.default-unit" value="true" />

      <!--            

                  <property name="javax.persistence.schema-generation.database.action" value="create"/>

      -->

       

                   <property name="hibernate.hbm2ddl.auto" value="update" />

                   <property name="hibernate.show_sql" value="false" />

                  <property name="hibernate.format_sql" value="false" />

                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />

                  <property name="hibernate.connection.isolation" value="1" />

       

                  <!-- Configuring Connection Pool -->

                  <property name="hibernate.c3p0.min_size" value="5" />

                  <property name="hibernate.c3p0.max_size" value="20" />

                  <property name="hibernate.c3p0.timeout" value="500" />

                  <property name="hibernate.c3p0.max_statements" value="50" />

                  <property name="hibernate.c3p0.idle_test_period" value="2000" />

              </properties>

          </persistence-unit>

      </persistence>