Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java持久性错误没有有效的提供程序_Java_Hibernate_Spring Boot - Fatal编程技术网

Java持久性错误没有有效的提供程序

Java持久性错误没有有效的提供程序,java,hibernate,spring-boot,Java,Hibernate,Spring Boot,我试着跟随教程。当他们运行代码时,它是成功的。当我运行代码时,我得到一个错误,上面写着警告:javax.persistence.spi::找不到有效的提供程序。我查看了文档并明确定义了实体/提供程序。对于.jpa.HibernatePersistenceProvider,我确实有一些红色错误字体,因为它说它无法解析类。这是主要课程 @PersistenceUnit(unitName = "org.hibernate.tutorial.jpa") private static EntityMana

我试着跟随教程。当他们运行代码时,它是成功的。当我运行代码时,我得到一个错误,上面写着
警告:javax.persistence.spi::找不到有效的提供程序。
我查看了文档并明确定义了实体/提供程序。对于
.jpa.HibernatePersistenceProvider
,我确实有一些红色错误字体,因为它说它无法解析类。这是主要课程

@PersistenceUnit(unitName = "org.hibernate.tutorial.jpa")
private static EntityManagerFactory entityManagerFactory;

public static void main(String[] args){

    entityManagerFactory = Persistence.createEntityManagerFactory("org.hibernate.tutorial.jpa");

    Client client = new Client();
    client.setId(2);
    client.setName("bob");

    Bank bank = new Bank();
    bank.setName("wells fartgo");

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    entityManager.getTransaction().begin();

    entityManager.persist(client);
    entityManager.persist(bank);
    entityManager.getTransaction().commit();

    entityManagerFactory.close();
}
/resources/WEB\u-INF中的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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_1.xsd">
<persistence-unit name="org.hibernate.tutorial.jpa">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <properties>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/classicmodels"/>
        <property name="hibernate.connection.autocommit" value="false"/>
        <property name="hibernate.connection.username" value="root"/>
        <property name="hibernate.connection.password" value=""/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
        <property name="hibernate.connection.CharSet" value="utf8"/>
        <property name="hibernate.connection.characterEncoding" value="utf8"/>
        <property name="hibernate.connection.useUnicode" value="true"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>

        <property name="hibernate.cache.region.factory_class"
        value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
        <property name="hibernate.javax.cache.provider" value="org.ehcache.jsr107.EhcacheCachingProvider"/>
        <!--use second level cache-->
        <property name="hibernate.cache.use_second_level_cache" value="true"/>
        <!--use 3rd level cache-->
        <property name="hibernate.cache.use_query_cache" value="true"/>
    </properties>
</persistence-unit>

org.hibernate.jpa.HibernatePersistenceProvider

还有我的pom.xml

<dependencies>
    <dependency>
        <groupId>org.clojure</groupId>
        <artifactId>java.jdbc</artifactId>
        <version>0.7.0-alpha3</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>6.0.0.Alpha2</version>
        <type>pom</type>
    </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate-core-version}</version>
        </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>LATEST</version>
    </dependency>
</dependencies>

org.clojure
java.jdbc
0.7.0-3
org.hibernate
冬眠核心
6.0.0.2
聚甲醛
org.hibernate
休眠实体管理器
${hibernate核心版本}
org.hibernate.javax.persistence
hibernate-jpa-2.0-api
最新的

main(bank/client)中的类只有getter和setter,因此没有任何错误。如果有人能让我知道如何成功运行这个演示,那就太好了。谢谢

首先,不要使用全新的阿尔法版本;使用5.x系列。此外,您的
type:pom
告诉Maven不要拉入实际的
hibernate核心,只是一些元数据。去掉它,你就会没事了。最后,如果您使用的是Spring Boot,请不要使用该教程,只需添加
Spring Boot starter jpa
@chrylis我做了您建议的更改,现在我收到了此错误
2019年7月10日10:36:36 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation:hh000204:正在处理PersistenceUnitInfo[名称:org.hibernate.tutorial.jpa…]2019年7月10日10:36:36 PM org.hibernate.Version日志版本信息:HHH000412:hibernate核心{5.2.10.Final}2019年7月10日10:36:36 PM org.hibernate.cfg.Environment INFO:hh000206:hibernate.properties未找到
包括删除显式配置并让
spring boot starter jpa
为您处理,或者仅让Maven更改?我已经很长时间没有手动配置hibernate了,因此我不记得如何引导它。@chrylis我对maven做了更改。我应该在哪里添加
spring boot starter jpa
?请注意,我并不是说你应该这样做,但是你标记了这个问题
spring
spring boot
,但是你没有显示任何与spring相关的内容,只是手动启动Hibernate。如果你使用的是Spring,那么你应该让它为你做这件事;如果没有,那么我们应该重新标记,将你的更改编辑到问题中,然后等待其他人查看它。