EclipseLink,需要两个持久性单元的EntityManager [英] EclipseLink, EntityManager with two persistence units needed

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

问题描述

我有一个jar库A(或eclipse中的项目),它具有它自己的持久性单元(META-INF/persistence.xml)和一些实体类,以及另一个使用该持久性单元的项目(B).在项目B中,还存在持久性单元和实体类.

I have one jar library A (or project in eclipse), which has it's own persistence unit (META-INF/persistence.xml) and some entity classes, and another project (B) using this one. In project B there is also persistence unit and entity classes.

在项目BI中,需要同时使用项目A和项目B中的两个实体类.但是,如果我将"A"设置为持久性单元名称,则如果此查询在项目B中的实体中,则EntityManager无法创建命名查询. "作为持久性单元名称,它无法从项目A中的实体创建命名查询.错误消息是:

In project B I need to use both entity classes from project A and B. But if I set "A" as persistence unit name, EntityManager cannot create named query if this query is in entity from project B. If I set "B" as persistence unit name, it cannot create named queries from entities from project A. Error message is:

NamedQuery of name: MyEntityName.myQueryName not found.

持久性单元可以以某种方式包括其他持久性单元吗?还是有其他方法可以解决这个问题?

Can persistence units somehow include other persistence units? Or is there any other way to solve this problem?

推荐答案

EclipseLink 2.3引入了复合持久性单元,您可以创建一个持久性单元,该持久性单元实际上仅充当两个或多个实际持久性单元的容器.这样,您就可以在应用程序中使用此单个复合持久性单元,就好像您只有一个持久性单元一样.这应该满足您保持persistence.xml文件干净以使模型轻松同步到数据库的目标.很酷的东西.

EclipseLink 2.3 introduced Composite Persistence Units, which allows you to create a persistence unit that essentially acts only as a container for two or more actual persistence units. You are then able to use this single composite persistence unit in your application as if you had only one persistence unit. This should meet your goals of keeping your persistence.xml files clean for easy synchronization of your model to database. Pretty cool stuff.

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

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