2012-04-23 53 views
0

我在Glassfish上安裝了這個Web項目,但是由於出現了一些問題,我決定遷移到Tomcat。如何解決在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

回答

2

您可以檢查幾件事情在這裏:

  1. 你哈哈VE部署你的應用確保的persistence.xml下

WEB-INF/classes/META-IN˚F文件夾,請

  1. 你的提供商(日食JPA)罐子在classpath中,Eclipse的信封在構建路徑,並檢查是否這在部署的應用程序中可用。
+0

對不起,但是在哪裏找到包含eclipse中已部署項目的文件夾?在glassfish它正好在服務器文件夾下。 – 2012-04-23 18:35:50

+0

如果您從eclipse部署,那麼默認文件夾是您的 /。metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps。或者,你可以雙擊你的服務器,然後檢查你的部署路徑(它將在eclipse編輯器的服務器位置 – mprabhat 2012-04-23 18:39:11

+0

好的,所以persistence.xml在WEB-INF/classes/META-INF文件夾下可見。我是EclipseLink庫作爲我的項目上的用戶庫,因此我在標記選項卡上得到此警告'描述\t資源\t路徑\t位置\t類型 類路徑條目org.eclipse.jdt.USER_LIBRARY/EclipseLink 2.3.2 - Indigo不會導出或發佈Runtime ClassNotFoundExceptions可能會導致\t JetCar \t \t P/JetCar \t Classpath Dependency Validator Message'。但我仍然在部署上獲得庫 – 2012-04-23 18:46:00

相關問題