简体   繁体   English

javax.persistence.PersistenceException:EntityManager 没有持久性提供程序

[英]javax.persistence.PersistenceException: No Persistence provider for EntityManager

I am trying to set up a test REST project with Jersey using EclipseLink as ORM and Gradle.我正在尝试使用 EclipseLink 作为 ORM 和 Gradle 使用 Jersey 设置测试 REST 项目。

When i wanted to test the ORM functionality i encountered the following exception:当我想测试 ORM 功能时,我遇到了以下异常:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named TestPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.resttest.SeedTest.main(SeedTest.java:13)

Running the following code:运行以下代码:

package com.resttest;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.resttest.entity.User;

public class SeedTest
{
public static void main(String[] args)
{
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("TestPU");
    EntityManager em = factory.createEntityManager();

    em.getTransaction().begin();

    User user = new User();
    user.setEmail("Joe");
    user.setPassword("xxx");

    em.persist(user);
    em.getTransaction().commit();

    em.close();
}
}

My build.gradle file looks like this:我的 build.gradle 文件如下所示:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile 'javax.ws.rs:jsr311-api:1.1.1'

    compile 'com.sun.jersey:jersey-server:1.19.4'
    compile 'com.sun.jersey:jersey-core:1.19.4'
    compile 'com.sun.jersey:jersey-servlet:1.19.4'

    compile 'mysql:mysql-connector-java:5.1.47'
    compile 'org.eclipse.persistence:eclipselink:2.5.1'
}

This is my persistence.xml:这是我的persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">

<persistence-unit name="TestPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="root" />
    </properties>
</persistence-unit>

Answers to this question said you have to add the JPA Provider library to the classpath (although it was always asked with Hibernate) but EclipseLink is already added to my classpath so it cannot be that.这个问题的答案说你必须将 JPA Provider 库添加到类路径中(尽管它总是被 Hibernate 询问)但 EclipseLink 已经添加到我的类路径中,所以它不可能是那样。 What is the problem?问题是什么?

好吧,这很尴尬,但显然我的源文件夹设置之一在 eclipse 中丢失了,这就是为什么我的 persistence.xml 文件没有被识别的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.persistence.PersistenceException:名为aramis的EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named aramis 具有Java SE的JPA:javax.persistence.PersistenceException:EntityManager没有持久性提供程序 - JPA with Java SE: javax.persistence.PersistenceException: No Persistence provider for EntityManager javax.persistence.PersistenceException:没有名为EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named javax.persistence.PersistenceException:没有名为EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named jboss 7.0.1休眠javax.persistence.PersistenceException:EntityManager没有持久性提供程序 - jboss 7.0.1 hibernate javax.persistence.PersistenceException: No Persistence provider for EntityManager javax.persistence.PersistenceException:没有名为customerManager的EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named customerManager 持久性单元错误:javax.persistence.PersistenceException:没有命名 EntityManager 的持久性提供程序 - Persistence unit error: javax.persistence.PersistenceException: No Persistence provider for EntityManager named 线程“ main”中的异常javax.persistence.PersistenceException:没有名为EntityTest的EntityManager的持久性提供程序 - Exception in thread “main” javax.persistence.PersistenceException: No Persistence provider for EntityManager named databaseTest javax.persistence.PersistenceException:没有名为money-transfer的EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named money-transfer 线程“ main”中的异常javax.persistence.PersistenceException:名为lanceurApplication的EntityManager的持久性提供程序没有 - Exception in thread “main” javax.persistence.PersistenceException: No Persistence provider for EntityManager named lanceurApplication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM