2 Replies Latest reply on Dec 11, 2019 2:32 AM by nschweig

    Two databases with two persistence units - tables are created in wrong database

    nschweig

      Hi everyone,

       

      I got several applications with EJB, JPA and JSF in Wildfly 14.

       

      I use 2 databases, processenginemysql and testprocessdb2. I configured two XA-Datasources.

      Here is my persistence.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="2.0"
        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">
      
        <persistence-unit name="primary">
          <jta-data-source>java:jboss/datasources/ProcessEngine</jta-data-source>
          <properties>
            <!-- Properties for Hibernate -->
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="true" />
          </properties>
        </persistence-unit>
        
         <persistence-unit name="processEntities">
         <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <jta-data-source>java:/ProcessDBXADS</jta-data-source>
          <properties>
            <!-- Properties for Hibernate -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MariaDBDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
      
          </properties>
        </persistence-unit>
      
      </persistence>
      

       

       

      I checked all my entities if I use the right persistence unit: (for example)

      @PersistenceContext(unitName = "processEntities")

       

      When I start the server, the tables from persistence unit "processEntities" are added to the tables from persistence unit "primary" like the following:

       

      Database 1 processenginemysql:

      table1processengine

      table2processengine

      table3processengine

      table1testprocessdb2

      table2testprocessdb2

      table3testprocessdb2

       

      Database 2 testprocessdb2:

      table1testprocessdb2

      table2testprocessdb2

      table3testprocessdb2

       

      Does anyone have an idea?

      Thanks a lot,

      Nicole