Not loading the persistence provider class in runtime - rest

I have created RestService enabled with JPA(Generic 2.0 version). Using jersey jars and hibernate entity manager jar as dependencies.
Deployment is successfull in tomcat. But when any transaction is processed, getting below exception in runtime.
java.lang.ClassNotFoundException: javax.persistence.spi.PersistenceProvider
What could be the issue, not loading the persistence provider class even it is in the classpath ?

What do you mean with classpath? The library/jar of the Persistence Provider Hibernate and the JPA (javax.persistence) have to be in the ear/war file so that Tomcat is able to access them.
How do you create that ear/war file? With Maven? Then you have to set the dependencies at least to runtime.

Related

which spring-data-mongodb version is supported by Spring-boot 2.3.4 because I am getting this error while server startup locally

Failed to introspect Class [org.springframework.data.mongodb.config.MongoConfigurationSupport] from ClassLoader
java.lang.NoClassDefFoundError: org/springframework/data/support/IsNewStrategyFactory
Caused by: java.lang.ClassNotFoundException: org.springframework.data.support.IsNewStrategyFactory
Dependency versions are listed in an appendix of Spring Boot's reference documentation. In that appendix can see that Spring Boot 2.3.4.RELEASE uses 3.0.4.RELEASE of org.springframework.data:spring-data-mongodb by default.
If you use Spring Boot's dependency management, either by inheriting from spring-boot-starter-parent or importing spring-boot-dependencies, you can declare a dependency without a version and Spring Boot's dependency management will give you the correct version automatically. You can learn more about this in the reference documentation.

OpenJPA cannot read a persistence.xml document with JPA 2.1 and weblogic version 12.1.3

I am getting below error, I have deployed my ear file using JPA2.1, weblogic version 12.1.3 and am using EclipseLink 2.6.4.
EclipseLink jars, persistence jar part of weblogic pre path, also I have set TOPLINK on weblogic server.
Note: I have also copied com.oracle.weblogic.jpa21support_1.0.0.0_2-1 to weblogic pre path.
Plese guide some pointers on the below error.
This version of OpenJPA cannot read a persistence.xml document with
a version different from "1.0". Found: version "2.1" in "zip:/tgwjpa/tgwjpa-ejb-1.0-SNAPSHOT.jar!/META-INF/persistence.xml".

javax.persistence jar is not loaded into tomcat

I'm trying to run JPA servlet on Tomcat 8.
From my servlet I call method of a class named QueryDB.class located in another Eclipse project (JPA project, not WEB project).
But tomcat throws
SEVERE: Servlet.service() for servlet [MyRESTService] in context with path [/AutomationWeb] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: javax/persistence/Persistence] with root cause
java.lang.ClassNotFoundException: javax.persistence.Persistence
at java.net.URLClassLoader$1.run(Unknown Source)
...
Exception is thrown at line EntityManagerFactory emf = Persistence.createEntityManagerFactory( "AutomationDB_JPA" ); in QueryDB.class
I'm using Eclipse Mars with Maven. I have EclipseLink in my pom.xml defined:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.1</version>
</dependency>
I have following jars in my Application's WEB-INF/lib:
eclipselink-2.6.1.jar
javax.persistence-2.1.0.jar , it has javax/persistence/Persistence.class inside
There is no other SEVERE messages in the tomcat log.
What's wrong with this setup?
I also tried adding the persistence jar to apache-tomcat-8.0.28\lib , but got the same error.
Update: I moved Persistence.createEntityManagerFactory call to the servlet itself and got no classloader exception. So the question changes: why classloader used for QueryDB.class is different from servlet's classloader? Also, why classloader used in QueryDB.class does not see the Persistence.class, which is seen by the servlet's classloader?
Ok I've found a solution.
Excluded my JPA project from tomcat VM classpath
Converted my JPA project to the Utility project
Modified Deployment Assembly in my Web project properties so that it
will accept JPA project as .jar archive into WEB-INF/lib
I have no classloader exception anymore.

icefaces project deployment error : org.apache.catalina.LifecycleException: java.lang.NoSuchFieldError: SKIP_ITERATION

I'm trying to make new icefaces project which generated using: ICEfaces 3.3.0 project integration for Eclipse.
I didn't modify anything on the project. but when i try to run on the server, i got an error:
cannot Deploy MyProject
Deployment Error for module: MyProject:
Exception while loading the app : java.lang.Exception:
java.lang.IllegalStateException: ContainerBase.addChild:
start: org.apache.catalina.LifecycleException:
java.lang.NoSuchFieldError: SKIP_ITERATION
before that, I'm using ICEfaces 3.2.0 project integration for Eclipse and no problem.
I'm using Eclipse Indigo, GlassFish server 3, Mojarra 2.1.6
Thanks before
java.lang.NoSuchFieldError: SKIP_ITERATION
As per the javadoc, that field was added in JSF 2.1.
So, this error suggests that your webapp's runtime classpath is polluted with a JSF 2.0 API JAR file. Perhaps in the /WEB-INF/lib? Get rid of it. Glassfish already ships with JSF bundled, you don't necessarily need to supply your own. Or, from the other side on, this can also happen if you deploy to an ancient Glassfish instance which bundles JSF 2.0 and JSF 2.1 was actually bundled in your webapp in an attempt to upgrade it. If so, then you should edited the Glassfish config file sun-web.xml or glassfish-web.xml, depending on GF version. See for detail the answer to this related question: How to update Mojarra version in GlassFish

Deploying JPA 2 (OpenJPA) on Jboss 7.1.0-Final-Snapshot

I have deployed axis2 on Jboss 7.1.0 Final Snapshot. We have a service (.aar) which uses OPenJPA 2.1.
All the OpenJPA jars are packaged within the service archive.
When I start the server I see this error message
Constructor threw exception; nested exception is java.lang.RuntimeException: javax.persistence.PersistenceException: No Persistence provider for EntityManager named example
I have defined the provider in the persistence.xml as org.apache.openjpa.persistence.PersistenceProviderImpl
Structure of my Service is as follows,
SampleOpenJPAService.aar
|-lib
|-myJPAClasses.jar
Can anyone help me in understanding What is going wrong here.
regards,
sathwik