___ ___ erkimt Unable to build entity manager factory (JPA Hibernate) ______ qstntxt ___

I am trying to make a connection with Hibernate and JPA, but when trying to create the connection or persist some data it executes the following error:

  

Dec 04, 2018 2:02:45 PM org.hibernate.ejb.HibernatePersistence   WARN: logDeprecation HHH015016: Encountered to deprecated   javax.persistence.spi.PersistenceProvider   [org.hibernate.ejb.HibernatePersistence]; use   [org.hibernate.jpa.HibernatePersistenceProvider] instead. Dec 04, 2018   2:02:45 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN:   HHH015016: Encountered to deprecated   javax.persistence.spi.PersistenceProvider   [org.hibernate.ejb.HibernatePersistence]; use   [org.hibernate.jpa.HibernatePersistenceProvider] instead. Dec 04, 2018   2:02:45 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN:   HHH015016: Encountered to deprecated   javax.persistence.spi.PersistenceProvider   [org.hibernate.ejb.HibernatePersistence]; use   [org.hibernate.jpa.HibernatePersistenceProvider] instead. Dec 04, 2018   2:02:45 PM org.hibernate.jpa.internal.util.LogHelper   INFO: HHH000204: LogPersistenceUnitInformation   PersistenceUnitInfo [name: context ...] Dec 04, 2018 2:02:45 PM   INFO: HHH000412: hibernate Core   {4.3.0.Final} Dec 04, 2018 2:02:45 PM org.hibernate.cfg.Environment    INFO: HHH000206: hibernate.properties not found Dec 04, 2018   INFO: 2:02:45 PM org.hibernate.cfg.Environment buildBytecodeProvider   HHH000021: Bytecode provider name: javassist Dec 04, 2018 2:02:45 PM   org.hibernate.annotations.common.reflection.java.JavaReflectionManager    INFO: HCANN000001: Hibernate Commons Annotations   {4.0.4.Final} Dec 04, 2018 2:02:45 PM   org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   configure INFO: HHH000402: Using Hibernate built-in connection pool   (not for production use!) Unable to build entity manager factory

My pom.xml

%pre%

My persistence.xml

%pre%

My Main class

%pre%     
______ azszpr348573 ___

1

I am trying to make a connection with Hibernate and JPA, but when trying to create the connection or persist some data it executes the following error:

  

Dec 04, 2018 2:02:45 PM org.hibernate.ejb.HibernatePersistence   WARN: logDeprecation HHH015016: Encountered to deprecated   javax.persistence.spi.PersistenceProvider   [org.hibernate.ejb.HibernatePersistence]; use   [org.hibernate.jpa.HibernatePersistenceProvider] instead. Dec 04, 2018   2:02:45 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN:   HHH015016: Encountered to deprecated   javax.persistence.spi.PersistenceProvider   [org.hibernate.ejb.HibernatePersistence]; use   [org.hibernate.jpa.HibernatePersistenceProvider] instead. Dec 04, 2018   2:02:45 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN:   HHH015016: Encountered to deprecated   javax.persistence.spi.PersistenceProvider   [org.hibernate.ejb.HibernatePersistence]; use   [org.hibernate.jpa.HibernatePersistenceProvider] instead. Dec 04, 2018   2:02:45 PM org.hibernate.jpa.internal.util.LogHelper   INFO: HHH000204: LogPersistenceUnitInformation   PersistenceUnitInfo [name: context ...] Dec 04, 2018 2:02:45 PM   INFO: HHH000412: hibernate Core   {4.3.0.Final} Dec 04, 2018 2:02:45 PM org.hibernate.cfg.Environment    INFO: HHH000206: hibernate.properties not found Dec 04, 2018   INFO: 2:02:45 PM org.hibernate.cfg.Environment buildBytecodeProvider   HHH000021: Bytecode provider name: javassist Dec 04, 2018 2:02:45 PM   org.hibernate.annotations.common.reflection.java.JavaReflectionManager    INFO: HCANN000001: Hibernate Commons Annotations   {4.0.4.Final} Dec 04, 2018 2:02:45 PM   org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   configure INFO: HHH000402: Using Hibernate built-in connection pool   (not for production use!) Unable to build entity manager factory

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>gpnet.com.br.api</groupId>
    <artifactId>Api</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <java-version>1.8</java-version>
        <spring-version>5.0.4.RELEASE</spring-version>
        <jpa-version>2.0.4.RELEASE</jpa-version>
        <hibernate-version>4.3.0.Final</hibernate-version>
        <mysql-version>6.0.4</mysql-version>
        <hibernate-jpa-version>1.0.0.Final</hibernate-jpa-version>
    </properties>

    <dependencies>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${jpa-version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate-version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate-version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql-version}</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>${hibernate-jpa-version}</version>
        </dependency>


    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven</groupId>
                <artifactId>maven-plugin-api</artifactId>
                <version>3.3.3</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

My persistence.xml

<?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="context" transaction-type="RESOURCE_LOCAL">

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

        <!-- Configurações da string de conexão -->
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpa"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="root"/>
            <!-- Linguagem que o Hibernate irá usar para se comunicar com o banco -->
            <property name="hibernate.dialect" value="hibernate.dialect.MYSQL5Dialect"/>
            <!-- Mostrar as queries no console -->
            <property name="hibernate.show_sql" value="true"/>
            <!-- Atualizar o banco de acordo com alguma alteração -->

        </properties>

    </persistence-unit>
</persistence>

My Main class

package gpnet.com.br.main;

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

import gpnet.com.br.models.Usuario;
import gpnet.com.br.util.JPAUtil;

public class Main {

    public static void main(String[] args) {

        Usuario user = new Usuario();
        user.setNome("jose");
        user.setEmail("jose.silva");
        user.setSenha("123456");

        try {
            EntityManager em;
            EntityManagerFactory fact = Persistence.createEntityManagerFactory("context"); // Here it crashes
            em = fact.createEntityManager();
            em.getTransaction().begin();
            em.persist(user);
            em.getTransaction().commit();

        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
    
asked by anonymous 04.12.2018 / 18:06

2 answers

1

07.12.2018 / 12:49
0

Apparently, the JPA implementation you are using is deprecated.

In your persistence.xml, change the provider tag accordingly: <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

Note also that you need to tell JPA which classes are entities to persist by adding this tag after declaring the provider:

<class>gpnet.com.br.models.Usuario</class>
    
04.12.2018 / 19:16