【问题标题】:How to create the JPA OSGI bundle如何创建 JPA OSGI 包
【发布时间】:2013-02-23 23:45:30
【问题描述】:

我想用 JPA 2.0 创建 OSGI 持久性服务包。我使用 OpenJpa 作为持久性提供程序。

我尝试了一个支持 JPA 的 OSGI 示例包,但当我的客户调用持久性功能时遇到了问题。该服务无法创建 EntityManagerFactory。始终为空。

我使用 Apache Karaf 作为平台来安装服务。

目前我正在 eclipse 中创建一个 OSGI 包并将其导出为一个包并在 Karaf 中部署它。客户端可以调用服务。但问题是当我得到 EntityManagerFactory 时。

我正在使用下面的代码来获取 EntityManagerFactory。

  OpenJPAEntityManagerFactory emf = OpenJPAPersistence.createEntityManagerFactory
    ("StudentServiceProvider","META-INF/persistence.xml");

请告诉我如何使用 OpenJPA 创建 OSGI 持久性捆绑包。

【问题讨论】:

    标签: osgi openjpa apache-karaf osgi-bundle


    【解决方案1】:

    如果您使用的是 Karaf,最好使用 Karaf 的 Aries jpa 功能,该功能在 OSGi 环境中提供了很好的 JPA 集成。它避免了许多类加载问题,并允许您利用其他容器服务,如事务管理(如果需要)。您仍然可以使用 OpenJPA 作为您的 JPA 提供者。例如,请参阅 tutorial on JaxEnterthese slides which explain why JPA on its own has issues

    【讨论】:

      【解决方案2】:

      您可以像 Holly 推荐的那样查看我的 tutorial for JPA on OSGi using Apache Aries

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-25
        • 1970-01-01
        • 2010-12-08
        • 1970-01-01
        • 2013-08-18
        • 2023-03-08
        • 2011-12-25
        相关资源
        最近更新 更多