java - 没有名为 MyBuzzPersistence 的 EntityManager 持久性提供程序

标签 java jpa

我的 JPA 项目在带有 32 位 Eclipse IDE 的 32 位 Windows 7 上运行良好,但在带有 32 位 Eclipse IDE 的 64 位 Windows 8 上运行不正常。在此项目中,我通过创建“用户 DSN”(名为 MyBuzzDB )连接到 MS-Access。对于 64 位操作系统,我创建了 32 位 ODBC 对话中的用户 DSN。

我的项目中也有所有 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)

最佳答案

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

关于java - 没有名为 MyBuzzPersistence 的 EntityManager 持久性提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21708860/

相关文章:

java - 如何按照数组中的顺序对卡片进行排序到颜色类型

java - 如何区分 OnUserLeaveHint 最小化/关闭和选择新 Activity ?

java - 执行自定义查询时出现 Spring Data JPA : getting No aliases found in result tuple! 错误

spring - 如何在没有组件扫描的情况下设置 Spring Data JPA 存储库

java - Hibernate DDL 与 validator 注释

java - Spring 数据 JPA : Specification with "like" and Long

java - 使用 System.currentTimeMillis() 每秒运行一次代码

java - 处理:从matrix4x4获取Yaw、Pitch和Roll角

java - SpringBoot JWT安全如何

java - JPA实体怎么做