I am trying to create a Java application that will migrate an old schema to a new schema. I've chosen Java for the following reasons:
- I need to perform data sanitation.
- Business logic needs to be done to default previously null/bad data.
- We are using JPA for our server code anyway. Using this in a migration will ensure our data migration has the correct integrity constraints.
My problem is; that when I increase the number of JPA Entity classes it takes a very long time to instantiate the EntityManager. Is there anything I can do to speed this up?
persistence.xml
<?xml version="1.0" encoding="UTF-
<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="puMigration" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.myCompany.MyEntity</class>
. . .
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>
Java Code
Map<String, String> properties = new HashMap<>();
properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
properties.put("javax.persistence.jdbc.url", url);
properties.put("javax.persistence.jdbc.user", username);
properties.put("javax.persistence.jdbc.password", password);
// TODO Refactor, this call takes 2 minutes. Why?
EntityManagerFactory emf = Persistence.createEntityManagerFactory("puMigration", properties);
entityManager = emf.createEntityManager();