一个Persistence.xml中的两个持久性单元 [英] Two Persistence Unit in one Persistence.xml

查看:148
本文介绍了一个Persistence.xml中的两个持久性单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们创建了一些我们所有项目都会使用的库,这些库将提供我们所有系统的基本功能(登录,管理等)。但是应用程序本身可以使用另一个数据库。



我们所做的是创建具有两个持久单元的Persistence.xml。并将所有核心库实体打包在名为LN-model.jar的jar中,并将所有实体中的out测试应用程序打包在App-model.jar中。但由于某种原因,我们仍然会收到以下消息。


无法解析与persistence-context-ref-name对应的持久性单元[ xxxxlistener.InicializadorListener / em]在模块范围内调用[gfdeploy#/ Users / zkropotkine / WORK / SeguridadCore / dist / gfdeploy / SeguridadCore-war_war]。请验证您的申请。


这是我们的Persistence.xml

 < persistence version =1.0xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http:// www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0。 XSD> 

< persistence-unit name =xtransaction-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 =ytransaction-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>



顺便提一句jar中的Persistence.xml,我们添加到我们的企业项目(EAR)。

解决方案

问题在于JPA是不知道哪个是持久性单元使用。当您只有一个持久性单元时,不会发生此问题。要解决此问题,请执行以下操作:



您需要指定一个持久性单元:Ejb中没有

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).

解决方案

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

这篇关于一个Persistence.xml中的两个持久性单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆