Search code examples
jakarta-eejpaeclipselink

EclipseLink Incorrectly Creating Tables (from another persistence unit)


I have a JAVE EE6 project using JPA 2 to persist entities into a MySQL database using Eclipselink 2.4.1 running on Glassfish 3.1.2.2.

I am storing the data in two separate databases, and for this I have two JNDI JDBC resources, and two JDBC connection pools. In the code I have two persistence units, each with different entities as shown below (note that there are also two persistence.xml files).

Project structure:

EAR
-EJBOne
--persistence.xml
---PersitenceUnitA
----(List of classes X)
-EJBTwo
--persistence.xml
---PersistenceUnitA
----(List of classes X + Z)
---PersistenceUnitB
----(List of classes Y)
----(orm.xml)

I have <property name="eclipselink.ddl-generation" value="create-tables"/> set in all of the persistence units, I also have <exclude-unlisted-classes>true</exclude-unlisted-classes> set.

What is happening is that upon deployment all of the entities in orm.xml in PersistenceUnitB are being created in PersistenceUnitA's database (as tables). Through trial and error I have found that the cause of this table generation is from the property in PersistenceUnitA in the persitence.xml in EJBTwo (i.e. the persistence.xml with both persistence units).

However the application otherwise runs correctly, looking only for entities in the specified persistence unit. I.e. using an EntityManager with unitName=PersistenceUnitB will indeed store the entity in PersistenceUnitB's database.

The classes manually listed in PersistenceUnitB (List of classes Y) using <class>name</class> are NOT generated in PersistenceUnitA's database - only those in orm.xml.

This is rather annoying, and if anyone has any information as to why this is happening that would be great.

Thanks.


Solution

  • orm.xml is looked for by default for both persistence units. Try renaming the file and explicitly list it in PersistenceUnitB