使用Eclipselink 2.7.7作为OpenLiberty的外部JPA



我已经在这几天了,可以使用一些帮助。我有一个使用EclipseLink 2.7.7和SDO特性的应用程序。为了测试,我将它作为一个独立的Java应用程序运行,使用作为EclipseLink提供的一部分下载的以下jar文件;

eclipselink.jar
commonj.sdo_2.1.1_v201112051852.jar

我需要这个代码在OpenLiberty下运行,使用会话Bean和实体。代码不能在OpenLiberty下工作,如果我只是依赖于内置的JPA2.2在自由。

我尝试按照这些说明来替换JPA: https://www.ibm.com/support/knowledgecenter/en/SS7K4U_liberty/com.ibm.websphere.wlp.zseries.doc/ae/twlp_dep_jpa.html

但是,说明列出了一堆我的EclipseLink下载中不存在的jar文件。例如,

<file name="${server.config.dir}/jpa/org.eclipse.persistence.asm.jar/>
<file name="${server.config.dir}/jpa/org.eclipse.persistence.core.jar"/>
<file name="${server.config.dir}/jpa/org.eclipse.persistence.jpa.jar"/>
<file name="${server.config.dir}/jpa/org.eclipse.persistence.antlr.jar"/>
<file name="${server.config.dir}/jpa/org.eclipse.persistence.jpa.jpql.jar"/>
<file name="${server.config.dir}/jpa/org.eclipse.persistence.jpa.modelgen.jar"/>

此外,我尝试将2个jar文件与我的代码捆绑在同一ear中,并部署它。但是,无论我做什么,只要我部署到自由号,"jpa2.2"功能被添加到服务器上,我的代码失败了。

有谁知道如何让Liberty停止添加"JPA2.2"特性?

在Liberty上部署EclipseLink作为第三方

不幸的是,正如您所发现的,Liberty为支持JPA 2.2而提供的EclipseLink并不包含EclipseLink SDO特性。我们将EclipseLink作为Java EE组件:JPA的持久性提供程序在WebSphere中发布。这意味着我们不会发布(然后支持)Java持久化规范(DBWS、SDO、MOXY(这是JAXB实现))没有强制要求的EclipseLink的其他部分。

正如您所发现的,如果您希望在Liberty中使用SDO功能,您将需要将其作为共享库提供。

我想指出Liberty的两个特性:

  1. jpa-2.2:该特性为您的应用程序提供了两件事:JPA API包(javax.persistence. js .)。*来自Java EE规范的包)和实现这些API包(EclipseLink)的持久性提供程序

  2. jpaContainer-2.2:这个特性提供了一个应用程序:JPA API bundle (javax.persistence。*来自Java EE规范的包)

如果您计划在Liberty中配置您自己的JPA 2.2支持的第三方持久性提供程序,建议您使用jpaContainer-2.2。这将为您提供您的提供者将要实现的JPA API包。这也意味着你不应该在你的共享库中提供你自己的javax.persistence.*API包,否则可能会有冲突。

我注意到你试图在你的共享库中使用eclipselink.jar。我强烈建议不要使用这个包。这是一个JSE引导包,包含所有EclipseLink特性和javax。持久性包。它是作为JSE中开发环境的便利包构建的,并不打算用于生产环境。因为它包含javax.persistence。*包,它可能会导致类加载问题,因为它与JPA API包WebSphere提供JPA功能(jpa-2.2jpaContainer-2.2)冲突

这也是KnowledgeCenter指令列出单独包(asm, antlr, core, jpa, jpql, modelgen)的原因。这些是WebSphere提供的用于支持JPA的包,您可以在Maven Central (https://mvnrepository.com/artifact/org.eclipse.persistence)上找到这些包的版本。如果您想使用SDO,我建议下载https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.sdo和它所需的任何其他依赖项(如org.eclipse.persistence.coreorg.eclipse.persistence.moxy)

Liberty功能更新问题

如果您正在Eclipse中部署Liberty(安装了IBM Liberty Developer Tools),并且在自动特性检测方面遇到问题,您可以从Preferences部分关闭它:

Window > Preferences > Server > Liberty Server
Uncheck `Enable automatic feature detection` 

最新更新