1
resposta

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named financas

Já busquei no fórum, e em outros locais na internet, problemas semelhantes e tentei realizar todas as soluções apontadas, mas infelizmente não obtive sucesso... Sou iniciante em JPA.

persistence.xml:

<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.caelum.financas.modelo.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://localhost/financas" />
            <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>

class TesteConta

package br.com.caelum.financas.teste;

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

import br.com.caelum.financas.modelo.Conta;

public class TesteConta {

    public static void main(String[] args) {
        Conta conta = new Conta();
        conta.setTitular("Marcelo");
        conta.setAgencia("2269");
        conta.setBanco("Santander - 033");
        conta.setNumero("01039967-2");

        EntityManagerFactory emf =  Persistence.createEntityManagerFactory("financas");
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();
        em.persist(conta);
        em.getTransaction().commit();

        emf.close();
        em.close();
    }
}
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;
    }

}
Estrutura do projeto e libs:
financas
    src
        br.com.caelum.financas.modelo
            Conta.java
        br.com.caelum.financas.teste
            TesteConta.java
        META-INF
            persistence.xml
    Referenced Libraries
        antlr-2.7.7.jar
        dom4j-1.6.1.jar
        jandex-1.1.0.Final.jar
        jboss-logging-annotations-1.2.0.Beta1.jar
        mysql-connector-java-5.1.48-bin.jar
        hibernate-commons-annotations-4.0.1.Final.jar
        hibernate-core-4.1.9.Final.jar
        hibernate-entitymanager-4.1.9.Final.jar
        hibernate-jpa-2.0-api-1.0.0.Final.jar
        javassit-3.17.1-GA.jar
        jboss-logging-3.1.0.GA.jar
        jboss-transaction-api_1.1_spec-1.0.0.Final.jar

Erro lançado ao tenta executar TesteConta:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named financas
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
    at br.com.caelum.financas.teste.TesteConta.main(TesteConta.java:18)
1 resposta

Seu Persistence.xml se encontra nesse classpath: src-->META-INF-->persistence.xml?