java 如何配置wildfly 使用EclipseLink?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25766872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 08:39:12  来源:igfitidea点击:

How to configure wildfly to use EclipseLink?

javaeclipselinkwildflywildfly-8

提问by Seb

i have installed wildfly 8.1 and because i have already a project configured to use EclipseLink, i have tried to configure wildfly to use it.

我已经安装了wildfly 8.1,并且因为我已经将一个项目配置为使用EclipseLink,所以我尝试将wildfly 配置为使用它。

However, i always the same error :

但是,我总是同样的错误:

at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
 at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
 at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
 at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
Caused by: javax.persistence.PersistenceException: JBAS011466: PersistenceProvider '
org.eclipse.persistence.jpa.PersistenceProvider
' not found
 at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.lookupProvider(PersistenceUnitServiceHandler.java:990)
 at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.addPuService(PersistenceUnitServiceHandler.java:258)
 at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.handleWarDeployment(PersistenceUnitServiceHandler.java:191)
 at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deploy(PersistenceUnitServiceHandler.java:126)
 at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:52)
 at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
 ... 5 more

I have though followed instructions of the official documentation, but nothing changed ! i have added the eclipseLink's jar to "modules\system\layers\base\org\eclipse\persistence\main" and the module.xml :

我虽然遵循了官方文档的说明,但没有任何改变!我已将 eclipseLink 的 jar 添加到“modules\system\layers\base\org\eclipse\persistence\main”和 module.xml 中:

<module xmlns="urn:jboss:module:1.3" name="org.eclipse.persistence">
    <resources>
        <resource-root path="jipijapa-eclipselink-1.0.1.Final.jar"/>
        <resource-root path="eclipselink.jar"/>
    </resources>

    <dependencies>
        <module name="asm.asm"/>
        <module name="javax.api"/>
        <module name="javax.annotation.api"/>
        <module name="javax.enterprise.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.validation.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="org.antlr"/>
        <module name="org.apache.commons.collections"/>
        <module name="org.dom4j"/>
        <module name="org.javassist"/>
        <module name="org.jboss.as.jpa.spi"/>
        <module name="org.jboss.logging"/>
        <module name="org.jboss.vfs"/>
    </dependencies>
</module>

Do you know what is the problem ?

你知道是什么问题吗?

Tks

塔克斯

Edit: My persistence.xml

编辑:我的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="AppPu">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>java:/H2Ds</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
    </persistence-unit>
</persistence>

采纳答案by Seb

Finally I solved the problem!

最后我解决了这个问题!

in fact, I have a composite unit, all persistence.xml are correct, but the persistence.xml which declared the composite unit was a bad statement of the provider:

事实上,我有一个复合单元,所有的persistence.xml都是正确的,但是声明复合单元的persistence.xml是提供者的错误声明:

<provider>
   org.eclipse.persistence.jpa.PersistenceProvider
</provider>

replaced by :

取而代之 :

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

and now work fine.

现在工作正常。

回答by graczun

New lines in provider section of persistence.xml won't work (how could it help?). Wildfly hasn't got provided eclipseLink implementation in libs. To fix this follow this steps:

persistence.xml 的 provider 部分中的新行将不起作用(这有什么帮助?)。Wildfly 尚未在库中提供 eclipseLink 实现。要解决此问题,请按照以下步骤操作:

  1. Download eclipselink.jar (or copy from your maven repo)
  2. Copy it to destination : ...Wildfly\modules\system\layers\base\org\eclipse\persistence\main
  3. Edit module.xml (same path). Add section <resource-root path="eclipselink.jar"><filter><exclude path="javax/**" /></filter></resource-root>
  1. 下载 eclipselink.jar(或从您的 Maven 仓库复制)
  2. 将其复制到目的地:...Wildfly\modules\system\layers\base\org\eclipse\persistence\main
  3. 编辑 module.xml(相同路径)。添加部分 <resource-root path="eclipselink.jar"><filter><exclude path="javax/**" /></filter></resource-root>

After server restart everything should work.

服务器重启后一切正常。

回答by Krzysztof Miksa

You need to add provider to persistence-unit in your persistence.xml:

您需要将提供程序添加到您的持久性单元persistence.xml

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

回答by 99Sono

The official documentaiton on how to configure the eclipselin module, and the required system property to active the vfs acrhieve factory impl are both given here:

关于如何配置 eclipselin 模块的官方文档,以及激活 vfs acrhieve factory impl 所需的系统属性都在这里给出:

https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-UsingEclipseLink

https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-UsingEclipseLink

For the module do something as:

对于模块做一些事情:

<module xmlns="urn:jboss:module:1.1" name="org.eclipse.persistence">
    <resources>
        <resource-root path="jipijapa-eclipselink-10.0.0.Final.jar"/>
        <resource-root path="eclipselink.jar">           
           <filter>
              <exclude path="javax/**" />
           </filter>
        </resource-root>
    </resources>

    <dependencies>
        <module name="asm.asm"/>
        <module name="javax.api"/>
        <module name="javax.annotation.api"/>
        <module name="javax.enterprise.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.validation.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="javax.ws.rs.api"/>
        <module name="org.antlr"/>
        <module name="org.apache.commons.collections"/>
        <module name="org.dom4j"/>
        <module name="org.jboss.as.jpa.spi"/>
        <module name="org.jboss.logging"/>
        <module name="org.jboss.vfs"/>
    </dependencies>
</module>
<module xmlns="urn:jboss:module:1.1" name="org.eclipse.persistence">
    <resources>
        <resource-root path="jipijapa-eclipselink-10.0.0.Final.jar"/>
        <resource-root path="eclipselink.jar">           
           <filter>
              <exclude path="javax/**" />
           </filter>
        </resource-root>
    </resources>

    <dependencies>
        <module name="asm.asm"/>
        <module name="javax.api"/>
        <module name="javax.annotation.api"/>
        <module name="javax.enterprise.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.validation.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="javax.ws.rs.api"/>
        <module name="org.antlr"/>
        <module name="org.apache.commons.collections"/>
        <module name="org.dom4j"/>
        <module name="org.jboss.as.jpa.spi"/>
        <module name="org.jboss.logging"/>
        <module name="org.jboss.vfs"/>
    </dependencies>
</module>

For the system property do something as:

对于系统属性,请执行以下操作:

<system-properties>
   ...
   <property name="eclipselink.archive.factory" value="org.jipijapa.eclipselink.JBossArchiveFactoryImpl"/>
</system-properties>
<system-properties>
   ...
   <property name="eclipselink.archive.factory" value="org.jipijapa.eclipselink.JBossArchiveFactoryImpl"/>
</system-properties>

Finally, do not start adding to your persistence.xml any container sepcific properties like:

最后,不要开始向您的 persistence.xml 添加任何容器特定属性,例如:

<property name="eclipselink.target-server" value="JBoss" />

This is completely wrong. Wildfly is already taking care of puting the proper target server platform in its:

这是完全错误的。Wildfly 已经负责将合适的目标服务器平台放入其:

org.jipijapa.eclipselink.EclipseLinkPersistenceProviderAdaptor

org.jipijapa.eclipselink.EclipseLinkPersistenceProviderAdaptor

Here is a sample of code from their class:

这是他们班级的代码示例:

  @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public void addProviderProperties(Map properties, PersistenceUnitMetadata pu) {
        if (!pu.getProperties().containsKey(ECLIPSELINK_TARGET_SERVER)) {
            properties.put(ECLIPSELINK_TARGET_SERVER, WildFlyServerPlatform.class.getName());
            properties.put(ECLIPSELINK_ARCHIVE_FACTORY, JBossArchiveFactoryImpl.class.getName());
            properties.put(ECLIPSELINK_LOGGING_LOGGER, JBossLogger.class.getName());
        }
    }
  @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public void addProviderProperties(Map properties, PersistenceUnitMetadata pu) {
        if (!pu.getProperties().containsKey(ECLIPSELINK_TARGET_SERVER)) {
            properties.put(ECLIPSELINK_TARGET_SERVER, WildFlyServerPlatform.class.getName());
            properties.put(ECLIPSELINK_ARCHIVE_FACTORY, JBossArchiveFactoryImpl.class.getName());
            properties.put(ECLIPSELINK_LOGGING_LOGGER, JBossLogger.class.getName());
        }
    }

YOu might want to make sure you debug this class, to make sure it gets invoked and makes your dynamic persistence unit properties all proper. But do not mess around with persistence.xml properties that are specific to the container. Wildfly is doing this properly and they add them themselves.

您可能希望确保调试此类,以确保它被调用并使您的动态持久性单元属性全部正确。但是不要乱用特定于容器的persistence.xml 属性。Wildfly 正在正确执行此操作,并且他们自己添加了它们。

So just follow their documentation, that is the best advice.

所以只需遵循他们的文档,这是最好的建议。

回答by weberjn

in EAP with a servicepack there is the trap that the org.eclipse.persistencemodule might actually be in the .overlays/tree (modules/system/layers/base/.overlays/).

在带有 servicepack 的 EAP 中存在一个陷阱,即org.eclipse.persistence模块实际上可能在.overlays/树中 ( modules/system/layers/base/.overlays/)。