如何合并/扩展来自不同JAR的持久性单元? [英] How can I merge / extend persistence units from different JARs?

查看:109
本文介绍了如何合并/扩展来自不同JAR的持久性单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将JPA持久性用于数据模型,并使用Eclipselink作为持久性提供程序.我有一个模块化(OSGi)应用程序,其中一个模块包含标准数据模型和一个持久性单元,该持久性单元自动包括程序包中的所有实体.持久性提供程序位于另一个模块中,该模块运行良好.

I use JPA persistence for my data models with Eclipselink as the persistence provider. I have a modular (OSGi) application and one of the modules contains the standard data model and a persistence unit that automatically includes all the entities from the package. The persistence provider is in another module, which works well.

现在,我希望第三个模块将一些实体添加到持久性单元.我怎么做?我找到了此解决方案,它似乎特定于我没有用的弹簧.该方法的摘要是编写一个后处理器,该后处理器挂接到持久性单元处理中,并手动合并persistence.xml文件中的<class>条目.

Now I want a third module to add some entities to the persistence unit. How do I do that? I found this solution, which seems specific to Spring which I'm not using. The summary of that approach is to write a post processor that hooks into the persistence unit processing and manually merges <class> entries from the persistence.xml files.

是否可以合并持久性单元?有人可以建议解决方法吗?

Is it possible to merge persistence units? Can anybody suggest a workaround?

推荐答案

首先,这是 Dynamic-JPA ,它们提供了一种动态更新实体的方法.我会先探讨这个选项.

First, here is a link on Dynamic-JPA they offer a way to update entities dynamically. I would explore this option first.


这是另一个链接( PDF )(来自OSGi),其中有一些关于持久性和EntityManagerFactory可能有用的顶级图表.


Here is another link (PDF) from OSGi there are a few top level diagrams dealing with persistence and the EntityManagerFactory that may be useful.


一种有趣的方法,但可能不相关


an interesting approach but may be unrelated

此处是创建持久单元的链接,而无需使用persistence.xml文件(您实际上无法做到,但是答案提供了对该问题的一些见识). philk提供了有关如何从persistence.xml文件中删除提供程序的建议.如果您遵循此方法,则可以将您的实体合并到一个特定的持久性单元中.

Here is a link on creating persistence units programmaticly without using a persistence.xml file (which you can't really do, but the answers offer some insight to the problem). philk offers a suggestion on how to remove the provider from the persistence.xml file. If you follow this method, you may be able to combine your entities into a specific persistence unit.

在Hibernate的美好时光里,我可以创建一个会话并 快速添加我的课程.似乎从未进入SUNS JPA 眼镜.但是,我已经从 persistence.xml,并使用EMF的属性将其交给EL.这 似乎还可以. persistence.xml中剩下的唯一内容是规范 的课程.我想公开该方法并不难 解析EL中的类名并为其创建ClassDescriptor 作为EL JPA提供商的公共方法. "

"Well in the good old days of Hibernate I could just create a session and add my classes to it on the fly. Seems that never made it into SUNs JPA specs. However I have completely removed the provider from the persistence.xml and hand it to EL using the properties of the EMF. This seems to work ok. The only thing left in the persistence.xml is the spec of the classes. I guess it would not be too hard to expose the method that parses the classname in EL and creates the ClassDescriptor for it as a public method of the EL JPA Provider. "

最后,我们提出了一个令人毛骨悚然的解决方案,已经有人建议这样做,然后在事后简单地编辑您的persistence.xml文件.我相信这会奏效(尽管我没有尝试过),但这绝对是一个选择.

Finally, we come to the hackish solution, doing has already been suggested, simply edit your persistence.xml files after the fact. I believe this would work (although, I haven't tried it) but it is definitely an option.

这篇关于如何合并/扩展来自不同JAR的持久性单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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