How do I resolve the "No Persistence Provider for Entitymanager named" error?

Asked

Viewed 4,566 times

2

When I try to execute the method Persistence.createEntityManagerFactory("Aluno") class Persistence i get the following error:

run:
abr 04, 2016 9:11:30 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
abr 04, 2016 9:11:30 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
abr 04, 2016 9:11:30 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Aluno
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at hibernatetutorial.Main.main(Main.java:21)
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 0 segundos)

In this message:

No Persistence Provider for Entitymanager named Student

He tells me there is no entity called Aluno, however, in my persistence unit I have already defined the class of this entity. I have researched it, but have not found the solution of the problem.

Follow my persistence unit:

<?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="HibernateTutorialPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>hibernatetutorial.Aluno</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/escolabd?zeroDateTimeBehavior=convertToNull"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.password" value="minhasenha"/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
    </properties>
  </persistence-unit>
</persistence>

Follow the structure of my project:

Estrutura do projeto

Follow the libraries I’m using:

bibliotecas

The IDE I’m using is the Netbeans IDE 8.0.2, and the Framework is Hibernate.

1 answer

3

According to class documentation Persistence the method createEntityManagerFactory receives a String that must be the name of your Unit persistence. By the configuration made in your persistence.xml you must pass the name as parameter HibernateTutorialPU

Update: To correct the error java.lang.NoClassDefFoundError: org/jboss/jandex/IndexViewjust add the following dependency on pom.xml Jandex is a tool that processes Java annotations within a directory or jar file, and saves the metadata within an index.

If you are using Maven

<dependency>
  <groupId>org.jboss</groupId>
  <artifactId>jandex</artifactId>
  <version>2.0.2.Final</version>
</dependency>
  • I passed the name of my persistence unit, but, not solved, gave another type of error see: java.lang.NoClassDefFoundError: org/jboss/jandex/IndexView.

  • Did you manage to solve this problem? I am having the same difficulty, and I did the above steps but it did not work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.