Reputation: 536
I have a javaEE application (webapp) on netbeans (running on glassfish server). I use the JPA ORM. I imported all the right jar on MAVEN. When I want to deploy the WAR file of this webapp on a distant server (running on tomcat) JPA makes it crash...
I have an error 500 on the server:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named com.mycompany_EmployeesManagementApplication2_war_1.0-SNAPSHOTPU javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) models.DataTransaction.(DataTransaction.java:31) controllers.SingleController.doGet(SingleController.java:37) javax.servlet.http.HttpServlet.service(HttpServlet.java:635) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Here is my pom.xml:
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>com.mycompany</groupId>
<artifactId>EmployeesManagementApplication2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>EmployeesManagementApplication2</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.5.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and here is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="com.mycompany_EmployeesManagementApplication2_war_1.0-SNAPSHOTPU" transaction-type="JTA">
<jta-data-source>java:app/awsrds</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
My persistence file is correctly located in ressources/META-INF
Thank you very much
Upvotes: 0
Views: 812
Reputation: 1157
The reason is that Tomcat is not a full Java EE server, it is only a servlet container and does not provide JPA, which Glassfish does. If you wish to use JPA with Tomcat then you need to include it in your WAR as a library.
If you are using pure JPA and not any Eclipselink features then you could use TomEE which includes Apache OpenJPA as an alternative JPA provider. Alternatively you could remain using GlassFish or Payara which include Eclipselink and do not need you to include it.
Upvotes: 2