2011-11-11 59 views
1

我正在構建JAX-RS Web服務(澤西島),現在我試圖開始使用JPA。我選擇了eclipselink來管理這種持久性。沒有用於EntityManager的持久性提供者名爲ws-persist

首先,我寫了一些junit測試用例,直到我弄清楚所有的東西都會如何結合在一起。

在我的persistence.xml(WEB-INF/persistence.xml中)我有:

<?xml version="1.0" encoding="UTF-8" ?> 
<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" 
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"> 
<persistence-unit name="ws-persist" transaction-type="RESOURCE_LOCAL"> 
    <class>beans.Change</class> 
    <properties> 
     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> 
     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3333/tomcat" /> 
     <property name="javax.persistence.jdbc.user" value="tomcat" /> 
     <property name="javax.persistence.jdbc.password" value="...." /> 
     <property name="eclipselink.ddl-generation" value="create-tables" /> 
     <property name="eclipselink.ddl-generation.output-mode" value="database" /> 
    </properties> 
</persistence-unit> 

在我的測試類我。

public class PersistenceTests { 

private EntityManager em = null; 

@Before 
public void setUp() throws Exception {  
    Properties propertiesMap = new Properties(); 
    propertiesMap.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE); 

    EntityManagerFactory factory = Persistence.createEntityManagerFactory("ws-persist", propertiesMap); 
    em = factory.createEntityManager(); 
} 

@After 
public void tearDown() throws Exception { 
} 

@Test 
public void testSetUp(){ 
    Assert.assertNotNull("Entity manager was null", em); 
    Assert.assertTrue("Entity manager wasn't connected", em.isOpen()); 
} 
} 

我有eclipselink.jar和兩個javax.persistence _ *。在我的WEB-INF/lib文件夾罐。 我收到了標題中提到的異常,有人可以幫我弄清楚如何解決這個問題嗎?

謝謝。

+0

似乎無法找到提供程序,請確保eclipselink.jar正確地在您的類路徑中。 – James

+0

當我在「web應用程序庫」下查看我的構建路徑時,會列出eclipselink.jar。 – Blaskovicz

回答

1

我會嘗試添加持久性提供在persistence.xml

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 

編輯)或移動的persistence.xml到META-INF文件夾。對於一個網絡應用程序,這必須在WEB-INF/classes

+0

我想我以前在那裏 - 這不能解決問題。 – Blaskovicz

+0

答案更新了另一個提示 –

+0

這是一個網絡應用程序,我在兩個位置都試過了,它沒有工作。 – Blaskovicz

相關問題