hibernate – java.lang.ClassNotFoundException:javax.persistence.spi.PersistenceProvider

I am using an application using JPA and Hibernate to try to deploy it on Tomcat 7.
It seems that I did not include all the libraries correctly because I received the following stack error:

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/amazontestapplcation] threw exception [java.lang.NoClassDefFoundError: javax/persistence/spi/ PersistenceProvider] with root cause
java.lang.ClassNotFoundException: javax.persistence.spi.PersistenceProvider
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController. doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass( Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source )
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java. net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java. security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang. ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.catalina. loader.WebappClassLoader.loadClass(WebappClassLoader.java:1698)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at javax.persistence.spi.PersistenceProviderResolverClassLoader$ CachingPersistenceProviderResolver.loadResolverClasses(PersistenceProviderResolverHolder.java:150)
at javax.persistence.spi.PersistenceProviderResolverHolder$Persis tenceProviderResolverPerClassLoader$CachingPersistenceProviderResolver.(PersistenceProviderResolverHolder.java:130)
at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader.getPersistenceProvider.ResolverPerClassLoader.getPersistenceProvider. Persistence.java:75)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com .example.service.EMFService.(EMFService.java:8)
at com.example.service.UserHandler.getAllUsers(UserHandler.java:30)
at com.example.managedbeans.LoginBean .authenticate(LoginBean.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect. DelegatingMethodAccessorImpl.invoke(Unknown Source )
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
at org.apache .el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter .invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java :315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun. faces.lifecycle.LifecycleImpl.execute(L ifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache .catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves .AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connecto r.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler. process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker. runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

You can See my WEB-INF/lib folder:

I also include these jars in my build path. Can anyone figure out why javax.persistence.spi.PersistenceProvider is not loaded?

Edit: I also inlucde my pom.xml file:



org.hibernate.javax.persistence
hibernate-jpa-2.0-api
1.0.1.Final
< /dependency>

org.hibernate
hibernate-core
4.1.0.Final


org.hibernate
hibernate-entitymanager
4.1.0.Final


javax
javaee-api
6.0


mysql
< artifactId>mysql-connector-java
5.1.18

When I I managed to make it work when I included the required jar in the Tomcat lib folder. But it was not a neat solution for me. I prefer to include the hibernate lib in the current project.

Update: I also included the entire structure of the project

Update: I still get the same error. I removed all jars from WEB-IN/lib and added them to the pom file as dependencies .
I posted the updated pom.xml file:


org.hibernate
< artifactId>hibernate-entitymanager
4.1.4.Final


org.hibernate .javax.persistence
hibernate-jpa-2.0-api
1.0.1.Final


org.hibernate
hibernate-core
4.1.4.Final


mysql
mysql-connector-java< br /> 5.1.21


org.slf4j
slf4j -jdk14
1.5.8

I also uploaded a picture of my classpath content:

Can anyone tell me why my application still fails to load the persistence class?

I only managed to get it working when I inlcuded the required jars in
the Tomcat lib folder. But this is not a neat solution for me. I
prefer inlude the hibernate lib only in the current project.

The required jar must be included in the lib folder, there is no way (unless you want to change the Tomcat configuration, what you should not do).

About our comment on your question: You should consider setting one Automatic build process (using the built-in war file) so that you don’t have to copy files manually (this will definitely make your problem unnecessary).

I am using The application of JPA and Hibernate tried to deploy it on Tomcat 7.
It seems that I did not include all the libraries correctly because I received the following stack error:

 SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/amazontestapplcation] threw exception [java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceProvider] with root cause
java.lang.ClassNotFoundException : javax.persistence.spi.PersistenceProvider
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net. URLC lassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader. defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass( Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run( Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source )
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)< br /> at org.apache.catalina.loader. WebappClassLoader.loadClass(WebappClassLoader.java:1698)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader$CachingerProvider loadResolverClasses(PersistenceProviderResolverHolder.java:150)
at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader$CachingPersistenceProviderResolver.(PersistenceProviderResolverHolder.java./>(PersistenceProviderResolverHolder./>(PersistenceProviderResolverHolder.php getPersistenceProviders(PersistenceProviderResolverHolder.java:88)
at javax.persistence.Persistence.getProviders(Persistence.java:75)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.example.service.EMFService.(EMFService.java:8)
at com.example.service.UserHandler.getAllUsers(UserHandler.java:30)
at com.example.managedbeans .LoginBean.authenticate(LoginBean.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun. reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.compon ent.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot. java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org .apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina .core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke( ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java: 118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run (Unknown Source)

You can see my WEB-INF/lib folder:

I also include these jars in my build path. Can anyone figure out why javax.persistence is not loaded .spi.PersistenceProvider?

Edit: I also inlucde my pom.xml file:



org.hibernate.javax.persistence
hibernate-jpa-2.0-api
1.0.1.Final
< /dependency>

org.hibernate
hibernate-core
4.1.0.Final


org.hibernate
hibernate-entitymanager
4.1.0.Final


javax
javaee-api
6.0


mysql
mysql-connector-java
5.1.18

When I I managed to make it work when I included the required jar in the Tomcat lib folder. But it was not a neat solution for me. I prefer to include the hibernate lib in the current project.

Update: I also included the entire structure of the project

Update: I still get the same error. I removed all jars from WEB-IN/lib and added them to the pom file as dependencies .
I posted the updated pom.xml file:


org.hibernate
< artifactId>hibernate-entitymanager
4.1.4.Final


org.hibernate .javax.persistence
hibernate-jpa-2.0-api
1.0.1.Final


org.hibernate
hibernate-core
4.1.4.Final


mysql
mysql-connector-java
5.1.21


org.slf4j
slf4j-jdk14< /artifactId>
1.5.8

I also uploaded a picture of my classpath content:

Can anyone tell me why my application still fails to load the persistence class?

I only managed to get it working when I inlcuded the required jars in
the Tomcat lib folder. But this is not a neat solution for me. I
prefer inlude the hibernate lib only in the current project.

The required jar must be included in the lib folder, There is no way (unless you want to change the Tomcat configuration, what you should not do).

About our comment on your question: You should consider setting up an automatic build process (using the built-in war file), so You don’t have to copy files manually (this will definitely make your problem unnecessary).

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4452 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.