如何解决雄猫上的持久性单元



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

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

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

我尝试将持久性.xml放在不同的文件夹中,但它没有奏效。

坚持不懈.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>

连接利用.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();
}

}

我的坚持.xml位于 src/META-INF 下

您可以在此处检查几件事:

  1. 部署应用程序后,请确保持久性.xml在

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

  1. 您的提供程序 (eclipse jpa) jar 位于类路径中,对于 Eclipse Env 在构建路径中,还要检查该 jar 在已部署的应用程序中是否可用。

相关内容

  • 没有找到相关文章

最新更新