"No Persistence provider for EntityManager" for Hibernate 5.x

4

Well, I have to update the version of hibernate that I was already trying to implement in my project to avoid bugs of the previous version, but I'm having a hard time persisting in the new version, since there were changes. >

The first was the Provider that is now done by the HibernatePersistenceProvider class. With this my persistence.xml was as follows:

<?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="bolsa" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistenceProvider</provider>
        <class>bean.Permissao</class>
        <class>bean.Usuario</class>
        <class>bean.Pagina</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <!-- dados da conexao -->
            <property name="javax.persistence.jdbc.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/bolsa" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="" />
            <!--  propriedades do hibernate -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.format_sql" value="true"/>

        </properties>
    </persistence-unit>
</persistence>

I try to capture the persistence drive according to documentation / a> from hibernate and my catch was as follows:

@PersistenceUnit
private final EntityManagerFactory factory;
private final EntityManager manager;

public __constructor() {
    this.factory = Persistence.createEntityManagerFactory("bolsa");
    this.manager = factory.createEntityManager();
}

However, it still gives the following error:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named bolsa
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at dao.Manager.<init>(Manager.java:36)
    at dao.Manager.create(Manager.java:28)
    at dao.Manager.create(Manager.java:24)
    at Service.AbstractService.execGet(AbstractService.java:47)
    at Service.AbstractService.get(AbstractService.java:77)
    at Filtro.Filtro.doFilter(Filtro.java:72)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

The configuration of my POM.xml with the hibernate files is:

<dependency>
   <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.11.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.11.Final</version>
</dependency>
<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>2.4.0</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>5.2.11.Final</version>
    <scope>provided</scope>
</dependency>

and my file configuration was:

    
asked by anonymous 19.10.2017 / 15:39