JPA-没有名为{{NAME_HERE}}的EntityManager的持久性提供程序 [英] JPA - No Persistence provider for EntityManager named {{NAME_HERE}}

查看:100
本文介绍了JPA-没有名为{{NAME_HERE}}的EntityManager的持久性提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正要为新应用程序创建一个后端,但我被困在配置JPA上. 我正在将GlassFish 5.0.0Hibernate 5.4.5.FinalMySQL一起使用.

I was about to create a backend for a new app and I got stuck at configuring JPA. I'm using GlassFish 5.0.0 and Hibernate 5.4.5.Final with MySQL.

我得到的错误是:

javax.servlet.ServletException: javax.persistence.PersistenceException: No Persistence provider for EntityManager named applicationDB

persistance.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
             version="2.2">

    <persistence-unit name="applicationDB">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>entities.CityEntity</class>
        <properties>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/world?serverTimezone=GMT"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="PASSWORD_HERE"/>
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
    </persistence-unit>
</persistence>

这是pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>backend</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.4.5.Final</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>


</project>

persistence.xml位于project/src/main/resources/META-INF

我访问我的REST端点之一,该端点依次调用应该测试JPA的方法,该方法基本上是这样做的:

I access one of my REST endpoints which in turn calls method that is supposed to test JPA, the method basically does this:

 EntityManagerFactory emf = Persistence.createEntityManagerFactory("applicationDB");
 EntityManager em = emf.createEntityManager();
 System.out.println("Entity: " + em.find(CityEntity.class, 5));

我找不到问题,有什么建议吗?

I can't spot the problem, any suggestions?

推荐答案

您看到了这个 https://stackoverflow.com/a/5121210/4962355 ? 建议使用hibernate-core.jar代替不推荐使用的hibernate-entitymanager.

Did you see this https://stackoverflow.com/a/5121210/4962355 ? It suggests to use hibernate-core.jar instead of the deprecated hibernate-entitymanager.

这篇关于JPA-没有名为{{NAME_HERE}}的EntityManager的持久性提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆