Eclipselink:如何获取每个包中的 EntityManager?
我想知道在每个 Bundle 中都有一个 EntityManager 的好方法。或者如何在 OSGi 程序中正确使用 JPA。
实际上,我有一个主包,用于加载 persistence.xml 文件并实例化 EntityManager。之后,我的主捆绑包通过服务将实体管理器的实例提供给其他捆绑包。因此,我使用了 equinox 服务的强大功能,并且我确信它必须存在另一个解决方案来在每个捆绑包中获取 EntityManager!
您知道另一种解决方案吗?或者实现这一目标的正确方法?
I wonder about a good way to have an EntityManager in each Bundle. Or how to use correctly JPA in an OSGi program.
Actually, I've one main bundle that loads the persistence.xml file and instantiates the EntityManager. After, my main bundle gives the instance of Entity manager to the other bundles via the services. So I use the power of the services of equinox and I'm sure it must exist an another solution to obtain an EntityManager in each bundle!
Do you know an another solution? or a correct way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否看过 EclipseLink wiki 上的 JPA OSGi 示例:http://wiki.eclipse .org/EclipseLink/Examples/OSGi
EclipseLink 是为 OSGi 打包并设计用于在 OSGi 中工作的。即将推出的 Eclipse Gemini JPA 增加了对通过新的 OSGi JPA 标准使用 EclipseLink 的支持(www.eclipse.org/gemini/jpa,Stackoverflow 不允许我发布完整的 URL)。我认为您会喜欢 Gemini JPA,因为该规范非常面向服务,并且可以通过任何捆绑包中的服务获取 EntityManagerFactory。我们正在努力实现 Gemini JPA 的初始里程碑,所以现在我会坚持使用 EclispeLink OSGi。
——肖恩
Have you taken a look at the JPA OSGi examples on the EclipseLink wiki: http://wiki.eclipse.org/EclipseLink/Examples/OSGi
EclipseLink is packaged for and designed to work in OSGi. And coming soon is Eclipse Gemini JPA which adds support for using EclipseLink through the new OSGi JPA standard (www.eclipse.org/gemini/jpa, Stackoverflow won't let me post the full URL). I think you'd like Gemini JPA as the spec is very service oriented and an EntityManagerFactory may be obtained via services from any bundle. We're working towards an initial milestone for Gemini JPA so for now I'd stick with EclispeLink OSGi.
--Shaun
如果您正在编写桌面应用程序(因此无法访问容器管理持久性),我建议您将 EntityManageFactory 发布为服务,而不是 EntityManager。然后,您的代码将具有以下布局:
在您的激活器中:
希望这有助于给您一个想法。
If you are writing a desktop application (and hence don't have access to container-manages persistence), I suggest you publish the EntityManageFactory as a service, and not the EntityManager. Your code will then have this layout:
And in your activator:
Hope this helps to give you an idea.