In Jdeveloper, I’ve created an application for Hibernate to provide DB Service using annotation to map class with DB, and I created jar of that and used in other project WebService. When i run the Hibernate Project Separately it works fine.
while deployment the web service application it reports NoSuchMethod Exception.
Error 500--Internal Server java.lang.ExceptionInInitializerError Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index; at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936) at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
After some research, its known that
The libraries used by the application after deployment is different than the library that is attached to the application in case of deployed application. The ClassLoader loads the class from different location.
The following code tells from which jar the class gets loaded.
Using this its been found that while running as an application it uses the right library (hibernate) from right location /WEB-INF/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar.
In deployed web service it uses older version of library which doesn’t have this method support. (its introduced in later versions) and its location was web logic /User_Home/Oracle/Middleware/modules/javax.persistence_220.127.116.11_1-0-2.jar (or the location of the weblogic libraries)
To solve this we can tell the weblogic to prefer the library from web-inf (our project libraries), if you don’t have one create it under WEB-INF directory.
by Adding the following in weblogic-application.xml (Application Resources)
<prefer-application-packages> <package-name>javax.persistence.*</package-name> <prefer-application-packages>
To understand reason behind this issue check this resource http://docs.oracle.com/cd/E15051_01/wls/docs103/programming/classloading.html