0

I'm trying to test my hibernate-maven app in Eclipse and when I run the method that get the name of the enttity class I get this exception:

jun. 01, 2021 9:52:51 P. M.       
javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver log
WARNING: javax.persistence.spi::No valid providers found.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for           
EntityManager named OtraReunionMas
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.linkedin.learning.otrareunionmas.utiles.EntityManagerUtil.getEntityManager(EntityManagerUtil.java:9)
at com.linkedin.learning.otrareunionmas.utiles.EntityManagerUtil.main(EntityManagerUtil.java:15)

This is the 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="OtraReunionMas" transaction-type="RESOURCE_LOCAL">
   <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
   <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306
      /otrareunionmas"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="xxxx"/>
      <property name="javax.persistence.jdbc.password" value="xxxx"/>
      <property name="javax.persistence.schema-generation.database.action" value="update"/>
      <property name="hibernate.dialect" value = "org.hibernate.dialect.MySQL8Dialect"/>
   </properties>
 </persistence-unit>
 </persistence>

This is the class with the method:

 package com.linkedin.learning.otrareunionmas.utiles;

 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;

 public class EntityManagerUtil {

 public static EntityManager getEntityManager() {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("OtraReunionMas");
    EntityManager manager = factory.createEntityManager();
    return manager;
 }

public static void main(String[] args) {
    EntityManager manager = EntityManagerUtil.getEntityManager();
    System.out.println("EntityManager class ==> " + manager.getClass().getCanonicalName());
}
}

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>com.linkedin.learning</groupId>
<artifactId>otrareunionmas</artifactId>
<version>0.0.1-SNAPSHOT</version>

<name>otrareunionmas</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   <maven.compiler.source>1.7</maven.compiler.source>
   <maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
   <dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>8.0.25</version>
   </dependency>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.4.16.Final</version>
  <type>pom</type>
</dependency>

</dependencies>
      <artifactId>maven-clean-plugin</artifactId>
      <version>3.1.0</version>
    </plugin>
    <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-
     core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <version>3.0.2</version>
    </plugin>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>
    </plugin>
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.1</version>
    </plugin>
    <plugin>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.0.2</version>
    </plugin>
    <plugin>
      <artifactId>maven-install-plugin</artifactId>
      <version>2.5.2</version>
    </plugin>
    <plugin>
      <artifactId>maven-deploy-plugin</artifactId>
      <version>2.8.2</version>
    </plugin>
    <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-
    core/lifecycles.html#site_Lifecycle -->
    <plugin>
      <artifactId>maven-site-plugin</artifactId>
      <version>3.7.1</version>
    </plugin>
    <plugin>
      <artifactId>maven-project-info-reports-plugin</artifactId>
      <version>3.0.0</version>
    </plugin>
  </plugins>
</pluginManagement>
</build>
</project>

I tried to change version number of the persistence, change the xmlns, the name of provider, but remains the exception.

reymagnus
  • 327
  • 2
  • 17

1 Answers1

0

Get rid of <type>pom</type> for hibernate-core at pom.xml

Andriy Slobodyanyk
  • 1,965
  • 14
  • 15