Estou tentado realizar uma conexão com o Hibernate e o JPA, porém ao tentar criar a conexão ou persistir algum dado ele executa o seguinte erro:
dez 04, 2018 2:02:45 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. dez 04, 2018 2:02:45 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. dez 04, 2018 2:02:45 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. dez 04, 2018 2:02:45 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation INFO: HHH000204: Processing PersistenceUnitInfo [ name: context ...] dez 04, 2018 2:02:45 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.3.0.Final} dez 04, 2018 2:02:45 PM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found dez 04, 2018 2:02:45 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist dez 04, 2018 2:02:45 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final} dez 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
Meu 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>
Meu 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>
Minha classe Main
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());
}
}
}