I can’t solve No Persistence Provider for Entitymanager named

Asked

Viewed 97 times

0

I searched on various forums, made all the suggestions I could find and still could not solve. I don’t know if it’s because of the archetype of the design, but it’s the pattern I’m using. Can someone please help me, I would be very grateful.

My pom.xml

<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>br.com.bolao</groupId>
<artifactId>BolaoVibao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.3.6.Final</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate- 
    entitymanager -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.3.6.Final</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.36</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/log4j/log4j -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <!-- JUnit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>

    <!-- JSF 2.2 -->
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.2.12</version>
    </dependency>

    <!-- Primefaces -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>6.2</version>
    </dependency>

    <!--Todos os temas gratuitos do Primefaces -->
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>all-themes</artifactId>
        <version>1.0.8</version>
    </dependency>

    <!-- OmniFaces -->
    <dependency>
        <groupId>org.omnifaces</groupId>
        <artifactId>omnifaces</artifactId>
        <version>1.11</version>
    </dependency>

</dependencies>

My persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">

<persistence-unit name="pu" transaction-type ="RESOURCE_LOCAL">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <class>br.com.bolao.model.Jogo</class>
    <class>br.com.bolao.model.Time</class>
    <class>br.com.bolao.model.Partida</class>
    <class>br.com.bolao.model.Campeonato</class>
    <class>br.com.bolao.model.Aposta</class>
    <class>br.com.bolao.model.Usuario</class>
    <class>br.com.bolao.model.Tabela</class>
    <class>br.com.bolao.model.TabelaUsuario</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <properties>
        <property name="javax.persistence.jdbc.driver" 
         value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" 
        value="jdbc:mysql://127.0.0.1:3306/bolaovibao" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="admin" />

        <property name="hibernate.dialect" 
         value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.hbm2ddl.auto" value="create" />

        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />

    </properties>
</persistence-unit>

My Entitymanager:

package br.com.bolao.util;

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

public class Exemplo {

public static void main(String[] args) {
    EntityManagerFactory emf = null;
    try {
        emf = Persistence.createEntityManagerFactory("pu");
        EntityManager em = emf.createEntityManager();

        em.clear();

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (emf != null) {
            emf.close();
        }
    }
}
}

META-INF is located like this:

METAINF

  • Try updating the Hibernate dependencies and put them in the same version. Hibernate-Commons-Annotations be in version 5.0 and the others are in version 5.3.

  • I put the 3 in the version 5.0.4 Final and now he pointed out another mistake: Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/SystemException

No answers

Browser other questions tagged

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