NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo
While deploying application with JPA 2.0 implementation in weblogic 10.x we used to get java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo error for the application deployment and usually you will be seeing this error in older versions of weblogic like here we faced below issue with WLS 10.3.6.
<Mar 8, 2016 1:27:12 AM IST> <Warning> <HTTP> <vmapp01g12app1> <MYServer> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1457380632336> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EntityManager' defined in URL [zip:C:/WL_HOME_1036/user_projects/domains/MYDOMAIN/servers/MYServer/tmp/_WL_user/MyApp01/epnft3/war/WEB-INF/lib/create_mbean.jar!/spring-config/appbean/applicationContext-appbean-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EntityManager' defined in URL [zip:C:/WL_HOME_1036/user_projects/domains/MYDOMAIN/servers/MYServer/tmp/_WL_user/MyApp01/epnft3/war/WEB-INF/lib/create_mbean.jar!/spring-config/appbean/applicationContext-appbean-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
you can follow below simple steps to avoid this error and fix it permanently:
java.lang.NoSuchMethodError :
Usually this error will come in case someone compiles a class against a different version of the class that is missing a method, than the one you are using when running the JVM. If the exception appears when calling a method on an object in a library, you are most likely using separate versions of the library when compiling and running. So right version of library required to fix the same.
Root Cause :
Application module uses hibernate JPA 2.0 but old weblogic versions(E.g: 10.3.6.0) supports only JPA 1.0 by default . So old hibernate JPA module needs to be preceded by the new JPA 2.0 to make it initialize and work properly or else the weblogic needs to be patched to higher patches to support JPA 2.0
If you are Ok with WLS upgrade then please check this document from Oracle for upgrading JPA 2.0(Java Persistence API) in weblogic.
For us upgrading weblogic was not a option so we have done below to get a quick fix the perticular server where we wanted JPA 2.0 support.
We had the JPA 2.0 jar as hibernate-jpa-2.0-api-1.0.1.Final.jar available in the applications ear file. So we copied the jar to a weblogic accessible location and pointed the jar file in classpath of that server. you can follow below steps to complete the same.
To add the jar to classpath follow below steps:
1. Login to weblogic admin console as admin user.
2. Click on lock and edit button and Navigate to servers > MyServer > Configuration > Server Start tab and update the classpath to below(single line).
C:/modules/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar;C:/modules/lib;C:/WL_HOM~1/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar;C:/PROGRA~1/Java/JDK17~1.0_8/lib/tools.jar;C:/WL_HOM~1/WLSERV~1.3/server/lib/weblogic_sp.jar;C:/WL_HOM~1/WLSERV~1.3/server/lib/weblogic.jar;C:/WL_HOM~1/modules/features/weblogic.server.modules_10.3.6.0.jar;C:/WL_HOM~1/WLSERV~1.3/server/lib/webservices.jar;C:/WL_HOM~1/modules/ORGAPA~1.1/lib/ant-all.jar;C:/WL_HOM~1/modules/NETSFA~1.0_1/lib/ant-contrib.jar
Note: you can check your CLASSPATH complete value from the weblogic startup logs. If you are also using WL 10.3.6 then you can use the above after updating the directory paths correctly.
3. Clear the tmp and cache folders of MyServer and start the MyServer from weblogic admin console.
4. The above steps will fix the issue.
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.