我在Ubuntu 12.04 LTS上运行了一个weblogic 10.3.4(是的,我知道它是一个遗留版本,但我不是那个版本......)。
在服务器上部署JPA(休眠)webapp时,我得到了
java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:629)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at weblogic.deployment.BasePersistenceUnitInfoImpl.initializeEntityManagerFactory(BasePersistenceUnitInfoImpl.java:393)
at weblogic.deployment.BasePersistenceUnitInfoImpl.initializeEntityManagerFactory(BasePersistenceUnitInfoImpl.java:386)
at weblogic.deployment.BasePersistenceUnitInfoImpl.<init>(BasePersistenceUnitInfoImpl.java:158)
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:629)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at weblogic.deployment.BasePersistenceUnitInfoImpl.initializeEntityManagerFactory(BasePersistenceUnitInfoImpl.java:393)
at weblogic.deployment.BasePersistenceUnitInfoImpl.initializeEntityManagerFactory(BasePersistenceUnitInfoImpl.java:386)
at weblogic.deployment.BasePersistenceUnitInfoImpl.<init>(BasePersistenceUnitInfoImpl.java:158)
Truncated. see log file for complete stacktrace
我可以看到 MANY 的人有同样的问题。
官方解决方案可在http://docs.oracle.com/cd/E17904_01/web.1111/e13720/using_toplink.htm#EJBAD1309找到 这告诉我补充一下:
#Enable JPA 2.0 functionality on WebLogic Server 10.3.4
export PRE_CLASSPATH=%BEA_HOME%\modules\javax.persistence_1.0.0.0_2-0-0.jar;%BEA_HOME%\modules\com.oracle.jpa2support_1.0.0.0_2-0.jar
到WL_HOME / common / bin / commEnv.sh
这没有用
我的weblogic.xml是以下
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
我还尝试了许多其他版本,因为有些版本增加了上述版本的问题。 java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<container-descriptor>
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.hibernate.*</package-name>
<package-name>javax.persistence.*</package-name>
</prefer-application-packages>
</container-descriptor>
而是给了我:
weblogic.application.ModuleException: Failed to load webapp: 'administration-gui.war'
at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:393)
at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:180)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:518)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
Truncated. see log file for complete stacktrace
Caused By: weblogic.deployment.EnvironmentException: Error processing persistence unit Offer of module administration-gui.war: Error instantiating the Persistence Provider class org.hibernate.ejb.HibernatePersistence of the PersistenceUnit Offer: java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence
at weblogic.deployment.BasePersistenceUnitInfoImpl.getPersistenceProvider(BasePersistenceUnitInfoImpl.java:375)
at weblogic.deployment.BasePersistenceUnitInfoImpl.initializeEntityManagerFactory(BasePersistenceUnitInfoImpl.java:393)
at weblogic.deployment.BasePersistenceUnitInfoImpl.initializeEntityManagerFactory(BasePersistenceUnitInfoImpl.java:386)
at weblogic.deployment.BasePersistenceUnitInfoImpl.<init>(BasePersistenceUnitInfoImpl.java:158)
at weblogic.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:39)
Truncated. see log file for complete stacktrace
答案 0 :(得分:2)
在我看来,您必须删除:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
因为你可能间接导入了ibernate-jpa-2.0-api或ibernate-jpa-2.1-api。
答案 1 :(得分:-1)
这需要设置为false:
<prefer-web-inf-classes>**false**</prefer-web-inf-classes>
如果你正在使用:
<container-descriptor>
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.hibernate.*</package-name>
<package-name>javax.persistence.*</package-name>
</prefer-application-packages>
</container-descriptor>