Rodrigo Cavalcante
Rodrigo Cavalcante

Reputation: 1597

How to solve persistence unit on Tomcat

I had this web project setup on Glassfish, but I decided to move to Tomcat since I was having some problems.

But now my persistence class is throwing the following error

Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named JetCarBd

I've tried placing the persistence.xml on different folders, but it haven't worked.

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence     http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="JetCarBd" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>br.com.jetcar.entity.Cliente</class>
<class>br.com.jetcar.entity.Endereco</class>
<class>br.com.jetcar.entity.Veiculo</class>
<class>br.com.jetcar.entity.Aluguel</class>
<class>br.com.jetcar.entity.Venda</class>
<class>br.com.jetcar.entity.Interesse</class>
<class>br.com.jetcar.entity.Funcionario</class>
<class>br.com.jetcar.entity.ItensAluguel</class>
<class>br.com.jetcar.entity.AcessorioAluguel</class>
<class>br.com.jetcar.entity.TestDrive</class>
<class>br.com.jetcar.entity.AcessorioVeiculo</class>
<class>br.com.jetcar.entity.Acessorio</class>
<class>br.com.jetcar.entity.Oficina</class>
<class>br.com.jetcar.entity.Manutencao</class>
<class>br.com.jetcar.entity.Reserva</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
  <property name="javax.persistence.jdbc.url"  value="jdbc:postgresql://localhost:5432/jetcar"/>
  <property name="javax.persistence.jdbc.password" value="postgres"/>
  <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
  <property name="javax.persistence.jdbc.user" value="postgres"/>
 </properties>
  </persistence-unit>
</persistence>

ConnectionUtil.java

package br.com.jetcar.connection;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * @author Jorge Oliveira
 */
public class ConnectUtil {

private  final EntityManagerFactory emf;

public ConnectUtil(){
    emf = Persistence.createEntityManagerFactory("JetCarBd");
}

public EntityManager getEntityManager() {
    return emf.createEntityManager();
}


}

My persistence.xml is located under src/META-INF

Upvotes: 0

Views: 9751

Answers (1)

mprabhat
mprabhat

Reputation: 20323

You can check for couple of things here:

  1. After you have deployed your application ensure that persistence.xml is available under

WEB-INF/classes/META-INF folder

  1. Your provider (eclipse jpa) jars are in the classpath, for Eclipse Env in build path, and also check if that is available in the deployed application.

Upvotes: 1

Related Questions