2012-01-25 44 views
1

我嵌入了德比數據庫,並且我使用jpa工作。這是我的persistence.xml:apache derby + jpa

<?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="pers"> 

     <class>entities.Leverancier</class> 
     <class>entities.Prijsproduct</class> 
     <class>entities.Product</class> 


    </persistence-unit> 
</persistence> 

我應該更改或添加以獲得此工作。當我運行我的代碼時,我得到以下內容:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named pers 
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) 
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33) 
at test.Test.main(Test.java:19) 
+0

什麼是您的持久性提供程序? –

+0

我在哪裏可以找到這個? – user999379

+1

什麼將用作JPA運行時提供程序(例如Hibernate,EclipseLink,...)?你需要在'persistence.xml'中提到它。 –

回答

2

您的persistence.xml是不正確的。請看下面的例子:

<persistence-unit name="MyAppPU" transaction-type="RESOURCE_LOCAL">  
    <!-- This is where you mention your JPA runtime provider e.g. it's EclipseLink here --> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>  

    <class>mypkg.MyEntity</class> 

    <properties> 
     <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/my_schema"/> 
     <property name="javax.persistence.jdbc.password" value="pass"/> 
     <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> 
     <property name="javax.persistence.jdbc.user" value="user"/> 
    </properties> 

</persistence-unit> 

你還必須確保你在classpath把你的JPA提供者的jar文件(連同德比客戶端JAR)。

+0

org.eclipse.persistence.jpa.PersistenceProvider 哪個jar文件呢? – user999379

+0

你可以從這裏下載它:http://www.eclipse.org/eclipselink/downloads/ –

+1

@ user999379:這應該有助於你開始使用JPA,EclipseLink和Derby:http://www.vogella.de/文章/ JavaPersistenceAPI/article.html#安裝 –