java - WARNING: jakarta.persistence.spi::No valid providers found - Stack Overflow

admin2025-04-22  1

I'm trying to work with Hibernate and I have tried all the solutions for similar problem, but still can't figure out what's wrong. I'm getting the below error

WARNING: jakarta.persistence.spi::No valid providers found.

I've tried adding more properties to persistence.xml, but still I'm getting the same error.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0"
         xmlns:xsi=";
         xsi:schemaLocation=".0.0 .0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>hibernate_intro</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <mavenpiler.source>19</mavenpiler.source>
        <mavenpiler.target>19</mavenpiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <!-- .hibernate/hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.6.5.Final</version>
            <type>pom</type>
        </dependency>
        <!--  -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
        </dependency>

        <!-- .zaxxer/HikariCP -->
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>6.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.36</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

</project>

src/main/java/resources/META-INF/persistence.xml

<persistence xmlns="; xmlns:xsi="; version="3.0" xsi:schemalocation=" .xsd">
    <persistence-unit name="my-persistence-unit">
<description>my persistence unit</description>
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
    <!-- database connection -->
    <property name="jakarta.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
    <property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test" />
    <property name="jakarta.persistence.jdbc.user" value="user" />
    <property name="jakarta.persistence.jdbc.password" value="password" />
</properties>
    </persistence-unit>
</persistence>

Product.java

package org.example.entities;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.Data;

@Entity
@Data
public class Product {

    @Id
    private int id;

    private String name;

    private int price;

}

I'm using IntelliJ IDEA. What is wrong with the above code?

转载请注明原文地址:http://anycun.com/QandA/1745300128a90561.html