How to fix the "No Persistence provider for EntityManager named" error?

2
When I try to execute the Persistence.createEntityManagerFactory("Aluno") method of 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

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

Follow my persistence drive:

<?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>

The structure of my project follows:

HerearethelibrariesI'musing:

The IDE I'm using is NetBeans IDE 8.0.2 , and the Framework is Hibernate.

    
asked by anonymous 05.04.2016 / 02:29

1 answer

3

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

Update: To correct the error java.lang.NoClassDefFoundError: org/jboss/jandex/IndexView you just add the following dependency in pom.xml Jandex is a tool that processes Java annotations inside 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>
    
05.04.2016 / 13:50