Estou tentando rodar o TesteConta mas dá uma exception
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.caelum.financas.teste.TesteConta.main(TesteConta.java:19)
Minha classe Conta
package br.com.caelum.financas.modelo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@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;
}
}
Minha classe TesteConta
package br.com.caelum.financas.teste;
import br.com.caelum.financas.modelo.Conta;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
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();
}
}
E meu arquivo persistence.xml
<persistence 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"
version="2.1">
<persistence-unit name="financas">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.com.caelum.financas.modelo.Conta</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /> <!-- DB Driver -->
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/financas" /> <!-- BD Mane -->
<property name="javax.persistence.jdbc.user" value="postgres" /> <!-- DB User -->
<property name="javax.persistence.jdbc.password" value="admin" /> <!-- DB Password -->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <!-- DB Dialect -->
<property name="hibernate.hbm2ddl.auto" value="update" /> <!-- create / create-drop / update -->
<property name="hibernate.show_sql" value="true" /> <!-- Show SQL in console -->
<property name="hibernate.format_sql" value="true" /> <!-- Show SQL formatted -->
</properties>
</persistence-unit>
</persistence>
Ja tentei ver os outros posts de dúvidas mas nada dá certo. Eu utilizo a IDE Intellij e criei um projeto Maven. Segue imagem das pastas do projeto https://prnt.sc/ldpu5r