EclipseLink错误地创建表(来自另一个持久性单元)

时间:2013-03-09 01:36:44

标签: java-ee jpa eclipselink

我有一个使用JPA 2的JAVE EE6项目,使用在Glassfish 3.1.2.2上运行的Eclipselink 2.4.1将实体持久化到MySQL数据库中。

我将数据存储在两个独立的数据库中,为此我有两个JNDI JDBC资源和两个JDBC连接池。在代码中我有两个持久性单元,每个单元具有不同的实体,如下所示(请注意,还有两个persistence.xml文件)。

项目结构:

EAR
-EJBOne
--persistence.xml
--- PersitenceUnitA
----(班级列表X)
-EJBTwo
--persistence.xml
--- PersistenceUnitA
----(类别X + Z列表)
--- PersistenceUnitB
----(班级列表Y)
----(orm.xml中)

我在所有持久性单元中都设置了<property name="eclipselink.ddl-generation" value="create-tables"/>,我也设置了<exclude-unlisted-classes>true</exclude-unlisted-classes>

发生的事情是,在部署时,PersistenceUnitB中orm.xml中的所有实体都是在PersistenceUnitA的数据库中创建的(如表)。通过反复试验,我发现这个表生成的原因来自EJBTwo中persitence.xml中的PersistenceUnitA中的属性(即带有两个持久性单元的persistence.xml)。

但是,应用程序否则正确运行,仅查找指定持久性单元中的实体。即使用带有unitName = PersistenceUnitB的EntityManager确实会将实体存储在PersistenceUnitB的数据库中。

使用<class>name</class>在PersistenceUnitB(类列表Y)中手动列出的类不会在PersistenceUnitA的数据库中生成 - 只在orm.xml中生成。

这很烦人,如果有人知道为什么会发生这种情况会有什么好处。

感谢。

1 个答案:

答案 0 :(得分:1)

对于两个持久性单元,默认情况下都会查找

orm.xml。尝试重命名文件并在PersistenceUnitB中明确列出它