如何解决Tomcat上的持久性单元

时间:2012-04-23 18:11:14

标签: tomcat jpa eclipselink persistence-unit

我在Glassfish上设置了这个Web项目,但是由于遇到了一些问题,我决定转移到Tomcat。

但是现在我的持久化类抛出了以下错误

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

我已经尝试将persistence.xml放在不同的文件夹上,但它没有用。

的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();
}


}

我的persistence.xml位于src / META-INF

1 个答案:

答案 0 :(得分:2)

您可以在这里查看几件事情:

  1. 部署应用程序后,确保在
  2. 下可以使用persistence.xml

    WEB-INF/classes/META-IN F文件夹

    1. 您的提供程序(eclipse jpa)jar位于类路径中,适用于构建路径中的Eclipse Env,并且还检查部署的应用程序中是否可以使用它。