weblogic.management.DeploymentException: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()

weblogic.management.DeploymentException: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()

在 Weblogic 上部署 EJB 应用程序:12.2.1,我遇到异常:

"weblogic.management.DeploymentException: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode"

我在 persistence.xml 中有以下配置来指定持久性提供程序

<persistence-unit name="entityManager">
<!-- Use Hibernate persistency -->  
<provider>org.hibernate.ejb.HibernatePersistence</provider>

及以下在 weblogic-application.xml

<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>javax.persistence.*</package-name>

在此异常之前,我遇到了从

解决的异常 "Error instantiating Persistence Provider class java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence"

从那以后我就面临这个例外

我在 WL_DOMAIN/lib 中提供了以下罐子:-

  1. hibernate-jpa-2.0-api-1.0.1.Final
  2. com.oracle.jpa2support_1.0.0.0_2-1
  3. 休眠
  4. dom4j

    在以下文件的类路径中也提供了如下 WL_DOMAIN ---setDomainEnv.cmd

    设置EXT_PRE_CLASSPATH=C:\Projects\GMPP-CBOSS\MFSS\MFSS\lib\hibernate\slf4j- api.jar;C:\Projects\GMPP-CBOSS\MFSS\MFSS\lib\hibernate\hibernate-jpa-api.jar

    ---TrivEnv.cmd

    设置类路径=C:\oracle\Middleware2\modules\javax.persistence_1.0.0.0_1-0- 2.jar;C:\oracle\Middleware2\modules\com.oracle.jpa2support_1.0.0.0_2- 1.jar;%类路径%

    ----commonEnv.cmd-----oracle_common/common/bin

    设置类路径=C:\oracle\Middleware2\modules\javax.persistence_1.0.0.0_1-0- 2.jar;C:\oracle\Middleware2\modules\com.oracle.jpa2support_1.0.0.0_2-1.jar;

下面是异常的堆栈跟踪:-

   <28 May, 2018, 3:38:26,86 PM IST> <Warning> <Deployer> <WL-149078> <Stack 
trace for message 149004
weblogic.management.DeploymentException: java.lang.NoSuchMethodError:   
javax.persistence.spi.PersistenceUnitInfo.getValidationMode() 
Ljavax/persistence/ValidationMode;
    at weblogic.application.internal.BaseDeployment .throwAppException 
   (BaseDeployment.java:132)
    at weblogic.application.internal.BaseDeployment.prepare 
   (BaseDeployment.java:242)
    at weblogic.application.internal.EarDeployment.prepare 
 (EarDeployment.java:66)
    at weblogic.application.internal. DeploymentStateChecker.prepare 
  (DeploymentStateChecker.java:158)
    at weblogic.deploy.internal.targetserver.AppContainerInvoker. 
  prepare(AppContainerInvoker.java:65)
    Truncated. see log file for complete stacktrace
  Caused By: java.lang.NoSuchMethodError: 
   javax.persistence.spi.PersistenceUnitInfo.getValidationMode() 
  Ljavax/persistence/ValidationMode;
    at org.hibernate.ejb.Ejb3Configuration.configure 
  (Ejb3Configuration.java:625)
    at org.hibernate.ejb.HibernatePersistence.createContainer 
  EntityManagerFactory (HibernatePersistence.java:73)
    at weblogic.persistence.BasePersistenceUnitInfo.initializeEntity 
 ManagerFactory(BasePersistenceUnitInfo.java:614)
    at weblogic.persistence.BasePersistenceUnitInfo. 
 init(BasePersistenceUnitInfo.java:202)
    at weblogic.persistence.BaseJPAIntegrationProvider. 
  createPersistenceUnitInfo(BaseJPAIntegrationProvider.java:54)
    Truncated. see log file for complete stacktrace
 >

可能在服务器类路径的开头和末尾添加了 javax.persistence_1.0.0.0_2-0-0.jar(在 DOMAIN_HOME/lib目录).

因此,同一服务器类路径中同一 jar 的两个版本会导致不一致。

解决方案 从 DOMAIN_HOME/lib 目录中删除 javax.persistence_1.0.0.0_2-0-0.jar。

来源:- https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=5zdu0pjx6_53&_afrLoop=302462572500859