我正在尝试创建一个将旧架构迁移到新架构的Java应用程序。我之所以选择Java,原因如下:
我的问题是;当我增加JPA实体类的数量时,实例化EntityManager需要很长时间。我有什么办法可以加快速度吗?
的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代码
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();