nov 26, 2018 1:41:14 AM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named financas
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at br.com.chatbot.TesteConta.main(TesteConta.java:18)
Classe Conta
package br.com.chatbot.entidades;
import javax.persistence.*;
@Entity
public class Conta {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String titular;
private String numero;
private String banco;
private String agencia;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitular() {
return titular;
}
public void setTitular(String titular) {
this.titular = titular;
}
public String getNumero() {
return numero;
}
public void setNumero(String numero) {
this.numero = numero;
}
public String getBanco() {
return banco;
}
public void setBanco(String banco) {
this.banco = banco;
}
public String getAgencia() {
return agencia;
}
public void setAgencia(String agencia) {
this.agencia = agencia;
}
}
Classe TesteConta
package br.com.chatbot;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import br.com.chatbot.entidades.Conta;
public class TesteConta {
public static void main(String[] args) {
Conta conta = new Conta();
conta.setTitular("Leonardo");
conta.setBanco("Caixa Economica");
conta.setAgencia("123");
conta.setNumero("456");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("financas");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(conta);
em.getTransaction().commit();
em.close();
emf.close();
}
}
Persistence
<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">
<!-- unidade de persistencia com o nome financas -->
<persistence-unit name="financas">
<!-- Implementação do JPA, no nosso caso Hibernate -->
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- Aqui são listadas todas as entidades -->
<class>br.com.chatbot.entidades.Conta</class>
<properties>
<!-- Propriedades JDBC -->
<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/financas?useTimezone=true&serverTimezone=UTC" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<!-- Configurações específicas do Hibernate -->
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Codigo Git hub
https://github.com/luizfernandosantoss/Curso-alura/tree/BancoDeDados/BancoDeDados/JPA