Javax.persistence.spi::no valid providers found.

The “javax.persistence.spi::no valid providers found” error typically occurs when using the Java Persistence API (JPA) and no valid JPA provider is found on the classpath. To resolve this issue, you need to make sure you have a JPA provider properly configured in your project.

Here is an example of how to configure JPA in a Maven-based project:

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>5.4.32.Final</version>
    </dependency>
  

Make sure to replace the artifactId, groupId, and version with the appropriate values for your JPA provider.

Additionally, you need to provide a persistence.xml file that defines the configuration for your JPA provider. Here is an example of a persistence.xml file:

    <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="myPersistenceUnit">
            <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
            <jta-data-source>jdbc/myDataSource</jta-data-source>
            <exclude-unlisted-classes>true</exclude-unlisted-classes>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                <property name="hibernate.show_sql" value="true"/>
            </properties>
        </persistence-unit>
    </persistence>
  

In this example, we are using the Hibernate JPA provider. Ensure that the <provider> tag points to the correct JPA provider for your project.

Remember to adjust the <jta-data-source> and other properties to fit your database setup. This configuration assumes the usage of MySQL as the database.

Same cateogry post

Leave a comment