一个 Persistence.xml 中有两个持久单元
我们创建了一些我们所有项目都会使用的库,这些库将提供我们所有系统的基本功能(登录、一些管理等)。但应用程序本身可以使用另一个数据库。
我们所做的是创建具有两个持久单元的 Persistence.xml。并将所有核心库实体打包在名为“LN-model.jar”的 jar 中,并将测试应用程序的所有实体打包在“App-model.jar”中。但由于某种原因,我们仍然收到以下消息。
无法解析名为 [gfdeploy#/Users/zkropotkine/WORK/SeguridadCore/dist/gfdeploy/SeguridadCore 的模块范围内与 persistence-context-ref-name [xxxxlistener.InicializadorListener/em] 对应的持久性单元-war_war]。请验证您的申请。
这是我们的 Persistence.xml
<persistence version="1.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_1_0.xsd">
<persistence-unit name="x" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/x</jta-data-source>
<jar-file>App-model.jar</jar-file>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>
<persistence-unit name="y" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/y</jta-data-source>
<jar-file>LN-model.jar</jar-file>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
顺便说一句,我们将 Persistence.xml 放入 jar 中,并将其添加到企业项目 (EAR) 中。
We created some libraries that all our projects will use, this libraries will provide the basic functionality of all our systems (login, some manage, etc). But the application itself could use another database.
What we did was to create the Persistence.xml with two persist units. And package all the core library entities in a jar called "LN-model.jar" and all of the entities of out test app in "App-model.jar". But for some reason we still obtain the following message.
Could not resolve a persistence unit corresponding to the persistence-context-ref-name [x.x.x.x.listener.InicializadorListener/em] in the scope of the module called [gfdeploy#/Users/zkropotkine/WORK/SeguridadCore/dist/gfdeploy/SeguridadCore-war_war]. Please verify your application.
Here's our Persistence.xml
<persistence version="1.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_1_0.xsd">
<persistence-unit name="x" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/x</jta-data-source>
<jar-file>App-model.jar</jar-file>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>
<persistence-unit name="y" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/y</jta-data-source>
<jar-file>LN-model.jar</jar-file>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
By the way we put the Persistence.xml in a jar, that we add to our Enterprise Project (EAR).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于 JPA 不知道要使用哪个持久单元。当您只有一个持久性单元时,不会发生此问题。要修复,请执行以下操作:
您需要在 Ejb 中指定一个持久性单元: @PersistenceContext(unitName="...")
The problem is that the JPA does not know which is the persistence unit to use. when you have only one persistence unit this problem does not occur. To fix do the following:
You need to specify a persistence unit : @PersistenceContext(unitName="...") in the Ejb that do not have
您可以添加注释:
或者您可以手动创建:
有关更多详细信息,请参阅以下链接: https://docs.oracle.com/html/E25034_01/usingmultipledbs.htm
非常有用,对我很有帮助!
You can add the annotations:
Or you can create it manually:
For more details, please see the following link: https://docs.oracle.com/html/E25034_01/usingmultipledbs.htm
is very useful, to me helped me!