Java 错误:EntityManager没有持久性提供程序

Java 错误:EntityManager没有持久性提供程序,java,hibernate,jpa,persistence,Java,Hibernate,Jpa,Persistence,我正试图开始我对Hibernate的理解。但我有个问题。 通过我的研究,我发现了很多东西,但没有任何东西可以解决我的问题。。 hibernate.ejb.HibernatePersistence是用红色写的 My persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="

我正试图开始我对Hibernate的理解。但我有个问题。 通过我的研究,我发现了很多东西,但没有任何东西可以解决我的问题。。 hibernate.ejb.HibernatePersistence是用红色写的

My persistence.xml

    <?xml version="1.0" encoding="UTF-8"?>
<persistence 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_2_0.xsd"
    version="2.0">

    <persistence-unit name="demojpa">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.format_sql" value="true"/>

            <!-- Configuration de la BDD -->
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/demojpa" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="" />

            <!-- Specifie le dialecte SQL utilisé pour communiquer avec la BDD -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MYSQLDialect"/>

            <!-- Indique a Hibernate de re-creer la BDD au lancement de l'applciation -->
            <property name="hbm2ddl.auto" value="create"/>

        </properties>
    </persistence-unit>
</persistence>
要完成我的根的图片。。。 因为我觉得这里面有个问题

谢谢大家的帮助

在persistence.xml中替换Hibernate版本5中删除的声明+

<provider>org.hibernate.ejb.HibernatePersistence</provider>

基本上,这会使红色消失

请注意,版本4.3.x中的Hibernate请参见表中支持的JPA版本。重要提示:您还应该在persistence.xml的头部声明以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<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_1.xsd"
             version="2.1">
这将为您提供完整的JPA2.1支持,并告诉ORM使用版本2.1

由于您刚刚开始,最好从版本或更高版本的Hibernate开始,因为这些版本的支持时间将超过4.3.x版本,4.3.x版本已经被视为仅用于维护,不再积极改进或开发

为了便于参考,前面已经讨论了这个问题

希望能有帮助

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<?xml version="1.0" encoding="UTF-8"?>
<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_1.xsd"
             version="2.1">