2010-07-12 46 views
6

我想創建一個能夠使用Java持久性的Bundle。爲了達到這個目的,我在Eclipse中創建了一個插件項目。在我的項目中,我創建了一個persistence.xml文件到META-INF。我ASLO加入我的MANIFEST.MF(進入depencies)這3個包:EclipseLink:否EntityManager的持久性提供者名爲

  1. javax.persistence.jar
  2. org.eclipse.persistence.jar
  3. org.eclipse.persistence.jar

然後,在我激活我用這樣的行來創建一個EntityManager:

factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); 
EntityManager em = factory.createEntityManager(); 

要執行我的包,我做了一個機生產線ct配置。當我運行我的產品配置,我得到這個錯誤:

javax.persistence.PersistenceException:否EntityManager的命名人

持久化提供我試着將我的persistence.xml的位置沒有成功。看來,任何包加載persistence.xml文件。也許,我沒有導入正確的軟件包?

你可以在這裏下載我的簡單捆綁:download

你能幫我找到一個解決方案或線索?

回答

4

嘗試在persistence.xml新增此標籤:

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

謝謝,但我堅持這一行。xml文件。 另一種解決方案? – user376112 2010-07-13 07:14:08

2

看來你沒有描述在MANIFEST.MF你的持久單元JPA-PersistenceUnits:頭。你可以在這裏找到EclipseLink的更多細節(1)。

(1):http://wiki.eclipse.org/Gemini/JPA/Documentation/CreatingAnApplication

+0

我解決了我的問題。我只有把清單中的類路徑這個包: - persistence.jar - eclipselink.jar - 的mysql-connector.jar 感謝 – user376112 2010-07-14 07:10:07

6

我已經解決了我的問題。我只有把清單中的類路徑這個包: - persistence.jar - eclipselink.jar - 的mysql-connector.jar

感謝

+0

我不知道我跟着你做添加一個清單給那些罐子文件?可以詳細說明一點嗎? – simgineer 2016-12-12 22:20:10

1

如果您從Eclipse中使用運行你的應用程序Maven,右鍵單擊JPA項目,選擇Properties,並查看是否有「Deployment Assembly」菜單項。如果是,請單擊部署程序集,單擊添加...按鈕,單擊Java構建路徑條目,然後選擇Maven Dependencies。確保eclipselink.jar是Maven的依賴項之一

1

我在Eclipse中運行的簡單項目中遇到同樣的錯誤。

事實證明,將META-INF目錄(包含persistence.xml)添加到我的類路徑中是錯誤的。

您必須在類路徑中包含其包含的dir(或jar)。從EclipseLink 2.5.1源代碼:

/** 
    * Search the classpath for persistence archives. A persistence archive is 
    * defined as any part of the class path that contains a META-INF directory 
    * with a persistence.xml file in it. Return a list of {@link Archive} 
    * representing the root of those files. It is the caller's responsibility 
    * to close all the archives. 
    * 
    * @param loader the class loader to get the class path from 
    */ 
    public static Set<Archive> findPersistenceArchives(ClassLoader loader){ 
     // allow alternate persistence location to be specified via system property. This will allow persistence units 
     // with alternate persistence xml locations to be weaved 
     String descriptorLocation = System.getProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT); 
     return findPersistenceArchives(loader, descriptorLocation); 
    } 
相關問題