"No Persistence Provider for Entitymanager" for Hibernate 5.x

Asked

Viewed 705 times

5

Well, you have to update the version of hibernate that was already I want to implement in my project to avoid bugs of the past version, but I’m having difficulty making the persistence in the new version, since there were changes.

The first was the Provider which is now done by the class HibernatePersistenceProvider. With that mine 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 unit according to documentation of Ibernate and my capture 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 makes the following mistake:

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 was left:

<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 the configuration of my file was:

inserir a descrição da imagem aqui

  • private __constructor()?

  • I modified it to public for better understanding, but this was by constructor implementation method, where I only call in class. But I don’t think it interferes, because the method is called.

  • The problem is not the private or public. The problem is that __constructor is not something that exists in Java. In Java, the constructor always has the same class name, otherwise you will get a build error.

1 answer

2


Browser other questions tagged

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