Versão correta do Log4j

3 respostas
luis_rodriguez

Olá pessoal,

Estou usando o Hibernate que já vem incorporado no NetBeans 6.7 e não estou conseguindo acertar a versão correta do Log4j, alguém sabe qual eu uso?

Valeu…

3 Respostas

luis_rodriguez

Bom, como ninguém respondeu, de repente eu tô fazendo a pargunta errada… O erro é o seguinte:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. %%%% Error Creating HibernateSessionFactory %%%% org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="hibernate.Pessoa"/> at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1600) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508) at org.hibernate.cfg.Configuration.configure(Configuration.java:1428) at hibernate.InitSessionFactory.initSessionFactory(InitSessionFactory.java:94) at hibernate.InitSessionFactory.getInstance(InitSessionFactory.java:50) at hibernate.GenericHibernateDAO.<clinit>(GenericHibernateDAO.java:24) at hibernate.TestandoHibernate.main(TestandoHibernate.java:33) Exception in thread "main" java.lang.ExceptionInInitializerError at hibernate.TestandoHibernate.main(TestandoHibernate.java:33) Caused by: org.hibernate.HibernateException: Could not initialize the Hibernate configuration at hibernate.InitSessionFactory.initSessionFactory(InitSessionFactory.java:111) at hibernate.InitSessionFactory.getInstance(InitSessionFactory.java:50) at hibernate.GenericHibernateDAO.<clinit>(GenericHibernateDAO.java:24) ... 1 more Java Result: 1

Alguma dica?

Andre_Brito

Mostra como você tá mapeando a classe Pessoa.

luis_rodriguez

Bom, o erro evoluiu pra isso aqui desde ontem:

2009-09-12 16:08:15,759 WARN [org.hibernate.cfg.AnnotationBinder] - <Package not found or wo package-info.java: hibernate> () 
Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
        at hibernate.GenericHibernateDAO.<init>(GenericHibernateDAO.java:28)
        at testegeralframe.Main.main(Main.java:45)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

O mapeamento tá assim:

package hibernate;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Luís Antonio de A. Rodriguez
 * Use, abuse e reinvente este trabalho intelectual
 * Se acrescentar alguma coisa, compartilhe comigo!!
 * [email removido]
 */
@Entity
@Table(name = "pessoa")
@NamedQueries({@NamedQuery(name = "Pessoa.findAll", query = "SELECT p FROM Pessoa p"), @NamedQuery(name = "Pessoa.findByIdPessoa", query = "SELECT p FROM Pessoa p WHERE p.idPessoa = :idPessoa"), @NamedQuery(name = "Pessoa.findByTxNomePessoa", query = "SELECT p FROM Pessoa p WHERE p.txNomePessoa = :txNomePessoa"), @NamedQuery(name = "Pessoa.findByTxSobrenomePessoa", query = "SELECT p FROM Pessoa p WHERE p.txSobrenomePessoa = :txSobrenomePessoa"), @NamedQuery(name = "Pessoa.findByDtDataNasc", query = "SELECT p FROM Pessoa p WHERE p.dtDataNasc = :dtDataNasc"), @NamedQuery(name = "Pessoa.findByNrIdade", query = "SELECT p FROM Pessoa p WHERE p.nrIdade = :nrIdade"), @NamedQuery(name = "Pessoa.findBySgLogradouro", query = "SELECT p FROM Pessoa p WHERE p.sgLogradouro = :sgLogradouro"), @NamedQuery(name = "Pessoa.findByTxNomeLogradouro", query = "SELECT p FROM Pessoa p WHERE p.txNomeLogradouro = :txNomeLogradouro"), @NamedQuery(name = "Pessoa.findByNmNumero", query = "SELECT p FROM Pessoa p WHERE p.nmNumero = :nmNumero"), @NamedQuery(name = "Pessoa.findByTxComplemento", query = "SELECT p FROM Pessoa p WHERE p.txComplemento = :txComplemento"), @NamedQuery(name = "Pessoa.findByTxBairro", query = "SELECT p FROM Pessoa p WHERE p.txBairro = :txBairro"), @NamedQuery(name = "Pessoa.findByTxCidade", query = "SELECT p FROM Pessoa p WHERE p.txCidade = :txCidade"), @NamedQuery(name = "Pessoa.findByTxEstado", query = "SELECT p FROM Pessoa p WHERE p.txEstado = :txEstado"), @NamedQuery(name = "Pessoa.findByTxCep", query = "SELECT p FROM Pessoa p WHERE p.txCep = :txCep"), @NamedQuery(name = "Pessoa.findByTxCpf", query = "SELECT p FROM Pessoa p WHERE p.txCpf = :txCpf")})
@SequenceGenerator(name="pessoa_id_generator", sequenceName="pessoa_id_pessoa_seq", allocationSize = 1)
public class Pessoa implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy=GenerationType.SEQUENCE , generator ="pessoa_id_generator" )
    @Column(name = "id_pessoa")
    private Integer idPessoa;
    @Basic(optional = false)
    @Column(name = "tx_nome_pessoa")
    private String txNomePessoa;
    @Basic(optional = false)
    @Column(name = "tx_sobrenome_pessoa")
    private String txSobrenomePessoa;
    @Basic(optional = false)
    @Column(name = "dt_data_nasc")
    @Temporal(TemporalType.DATE)
    private Date dtDataNasc;
    @Column(name = "nr_idade")
    private Integer nrIdade;
    @Basic(optional = false)
    @Column(name = "sg_logradouro")
    private String sgLogradouro;
    @Column(name = "tx_nome_logradouro")
    private String txNomeLogradouro;
    @Column(name = "nm_numero")
    private Integer nmNumero;
    @Column(name = "tx_complemento")
    private String txComplemento;
    @Column(name = "tx_bairro")
    private String txBairro;
    @Column(name = "tx_cidade")
    private String txCidade;
    @Column(name = "tx_estado")
    private String txEstado;
    @Column(name = "tx_cep")
    private String txCep;
    @Column(name = "tx_cpf")
    private String txCpf;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idPessoa")
    private Collection<Email> emailCollection;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "pessoa")
    private Paciente paciente;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "pessoa")
    private Fisioterapeuta fisioterapeuta;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idPessoa")
    private Collection<Fotos> fotosCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idPessoa")
    private Collection<Telefone> telefoneCollection;

    public Pessoa() {
    }

    public Pessoa(Integer idPessoa) {
        this.idPessoa = idPessoa;
    }

    public Pessoa(Integer idPessoa, String txNomePessoa, String txSobrenomePessoa, Date dtDataNasc, String sgLogradouro) {
        this.idPessoa = idPessoa;
        this.txNomePessoa = txNomePessoa;
        this.txSobrenomePessoa = txSobrenomePessoa;
        this.dtDataNasc = dtDataNasc;
        this.sgLogradouro = sgLogradouro;
    }

    public Integer getIdPessoa() {
        return idPessoa;
    }

    public void setIdPessoa(Integer idPessoa) {
        this.idPessoa = idPessoa;
    }

    public String getTxNomePessoa() {
        return txNomePessoa;
    }

    public void setTxNomePessoa(String txNomePessoa) {
        this.txNomePessoa = txNomePessoa;
    }

    public String getTxSobrenomePessoa() {
        return txSobrenomePessoa;
    }

    public void setTxSobrenomePessoa(String txSobrenomePessoa) {
        this.txSobrenomePessoa = txSobrenomePessoa;
    }

    public Date getDtDataNasc() {
        return dtDataNasc;
    }

    public void setDtDataNasc(Date dtDataNasc) {
        this.dtDataNasc = dtDataNasc;
    }

    public Integer getNrIdade() {
        return nrIdade;
    }

    public void setNrIdade(Integer nrIdade) {
        this.nrIdade = nrIdade;
    }

    public String getSgLogradouro() {
        return sgLogradouro;
    }

    public void setSgLogradouro(String sgLogradouro) {
        this.sgLogradouro = sgLogradouro;
    }

    public String getTxNomeLogradouro() {
        return txNomeLogradouro;
    }

    public void setTxNomeLogradouro(String txNomeLogradouro) {
        this.txNomeLogradouro = txNomeLogradouro;
    }

    public Integer getNmNumero() {
        return nmNumero;
    }

    public void setNmNumero(Integer nmNumero) {
        this.nmNumero = nmNumero;
    }

    public String getTxComplemento() {
        return txComplemento;
    }

    public void setTxComplemento(String txComplemento) {
        this.txComplemento = txComplemento;
    }

    public String getTxBairro() {
        return txBairro;
    }

    public void setTxBairro(String txBairro) {
        this.txBairro = txBairro;
    }

    public String getTxCidade() {
        return txCidade;
    }

    public void setTxCidade(String txCidade) {
        this.txCidade = txCidade;
    }

    public String getTxEstado() {
        return txEstado;
    }

    public void setTxEstado(String txEstado) {
        this.txEstado = txEstado;
    }

    public String getTxCep() {
        return txCep;
    }

    public void setTxCep(String txCep) {
        this.txCep = txCep;
    }

    public String getTxCpf() {
        return txCpf;
    }

    public void setTxCpf(String txCpf) {
        this.txCpf = txCpf;
    }

    public Collection<Email> getEmailCollection() {
        return emailCollection;
    }

    public void setEmailCollection(Collection<Email> emailCollection) {
        this.emailCollection = emailCollection;
    }

    public Paciente getPaciente() {
        return paciente;
    }

    public void setPaciente(Paciente paciente) {
        this.paciente = paciente;
    }

    public Fisioterapeuta getFisioterapeuta() {
        return fisioterapeuta;
    }

    public void setFisioterapeuta(Fisioterapeuta fisioterapeuta) {
        this.fisioterapeuta = fisioterapeuta;
    }

    public Collection<Fotos> getFotosCollection() {
        return fotosCollection;
    }

    public void setFotosCollection(Collection<Fotos> fotosCollection) {
        this.fotosCollection = fotosCollection;
    }

    public Collection<Telefone> getTelefoneCollection() {
        return telefoneCollection;
    }

    public void setTelefoneCollection(Collection<Telefone> telefoneCollection) {
        this.telefoneCollection = telefoneCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPessoa != null ? idPessoa.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pessoa)) {
            return false;
        }
        Pessoa other = (Pessoa) object;
        if ((this.idPessoa == null && other.idPessoa != null) || (this.idPessoa != null && !this.idPessoa.equals(other.idPessoa))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "hibernate.Pessoa[idPessoa=" + idPessoa + "]";
    }

}

Esse pojo foi gerado automaticamente pelo NetBeans, baseado no schema do BD, exceto algumas alteraçõe s que eu fiz nas annotations...

:? Vlw

Criado 11 de setembro de 2009
Ultima resposta 12 de set. de 2009
Respostas 3
Participantes 2