我的JPA项目在32位Windows 7和32位eclipse IDE上运行良好,但同样不适用于64位Windows 8和32位eclipse IDE。在这个项目中,我通过创建“用户DSN”(名为MyBuzzDB)连接到MS-Access。对于64位操作系统,我创建了 用户DSN在其32位ODBC对话中。
我的项目中也有所有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 :(得分: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