Comecei a fazer este curso dentro da Formação Java e tive problemas com o código que baixei na primeira aula. Ao rodar o código TesteJPA.java abaixo (não alterei nada nos códigos que baixei da aula):
package br.com.caelum.financas.jpa;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import br.com.caelum.financas.modelo.Conta;
public class TesteJPA {
public static void main(String[] args) {
Conta conta = new Conta();
conta.setTitular("Maria dos Santos");
conta.setBanco("Caixa");
conta.setAgencia("043");
conta.setNumero("54321");
/**
* Usando HSQLDB
*/
// EntityManagerFactory emf = Persistence
// .createEntityManagerFactory("contas-hsqldb");
/**
* Usando PostgreSQL
*/
// EntityManagerFactory emf = Persistence
// .createEntityManagerFactory("contas-postgres");
/**
* Usando MySQL
*/
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("contas-mysql");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(conta);
em.getTransaction().commit();
em.close();
}
}
Ocorre a seguinte mensagem de erro no console do Eclipse:
fev 27, 2020 9:59:15 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
fev 27, 2020 9:59:15 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.9.Final}
fev 27, 2020 9:59:15 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
fev 27, 2020 9:59:15 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
fev 27, 2020 9:59:15 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
fev 27, 2020 9:59:15 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
fev 27, 2020 9:59:15 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
fev 27, 2020 9:59:15 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/contas]
fev 27, 2020 9:59:15 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {autocommit=true, release_mode=auto, user=root}
fev 27, 2020 9:59:19 PM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure
WARN: HHH000342: Could not obtain connection to query metadata : Communications link failure