2014-02-11 58 views
1

我的JPA項目在32位eclipse IDE的32位Windows 7上運行良好,但同樣不適用於帶有32位eclipse IDE的64位Windows 8。在這個項目中,我通過創建「用戶DSN」(名爲MyBuzzDB)連接到MS-Access。對於64位操作系統,我在其32位ODBC對話中創建了 用戶DSN。No EntityManager的持久性提供程序名爲MyBuzzPersistence

我的項目中也有所有的JAR。

任何幫助將不勝感激。

這裏是我的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.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_1_0.xsd">

<persistence-unit name="MyBuzzPersistence"> 
    <provider>oracle.toplink.essentials.PersistenceProvider</provider> 

    <class>com.myBuzz.entity.AuthenticateEntity</class> 
    <properties> 

    <property name="toplink.jdbc.url" value="jdbc:odbc:MyBuzzDB" /> 
    <property name="toplink.jdbc.user" value="" /> 
    <property name="toplink.jdbc.driver" value="sun.jdbc.odbc.JdbcOdbcDriver" /> 
    <property name="toplink.jdbc.password" value="" /> 

    </properties> 
</persistence-unit> 

</persistence>


堆棧跟蹤是:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyBuzzPersistence 
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) 
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) 
at com.myBuzz.service.AuthenticationService.authenticateUser(AuthenticationService.java:17) 
at com.myBuzz.manager.AuthenticationManager.authenticateUser(AuthenticationManager.java:16) 
at com.myBuzz.test.DBTest.main(DBTest.java:21) 
+0

這聽起來像的persistence.xml是不在正確的位置,它在META-INF中? – Koitoer

+0

這是一個重複的http://stackoverflow.com/questions/19322827/null-after-persistence-createentitymanagerfactorypersistence-unit-name/19327322#19327322 – cmd

+0

大多數時候我們會得到這個錯誤的其他錯誤以及.if你的persistence.xml在你的META-INF中,然後發佈完整的stacktrace。所以我們可以幫助你。 –

回答

0

persistence.xml中是不是在正確的位置...

您需要將persistence.xml文件移動到適當的位置,那就是META-INF/persistence.xml文件添加到源文件夾的根目錄。

以下是從JPA規範

A persistence.xml file defines a persistence unit. The persistence.xml file is 
located in the META-INF directory of the root of the persistence unit. 

持久性單元的根是這裏的關鍵。

如果你是一個非Java EE應用程序

The jar file or directory whose META-INF directory contains the persistence.xml 
file is termed the root of the persistence unit. 

如果你是在一個的Java EE應用程序,以下是有效的

In Java EE environments, the root of a persistence unit must be one of the following: 
• an EJB-JAR file 
• the WEB-INF/classes directory of a WAR file[80] 
• a jar file in the WEB-INF/lib directory of a WAR file 
• a jar file in the EAR library directory 
• an application client jar file 
相關問題