Problemas com Hibernate

7 respostas
pauloperes

Olá Pessoal, estou tentando utilizar o hibernate no netbenas, sou iniciante, vejam o código:

public class Aluno {

// Atributos da Classe

private int RA;

private String nome;

private String email;

private String telefone;

private String celular;

private String curso;

private String serie;

private String campus;
/** Creates a new instance of Aluno */
public Aluno() {
}

// Métodos Set e Get
public int getRA(){
    return RA;
}

public void setRA(int ra){
    this.RA = RA;
}

public String getNome(){
    return nome;
}

public void setNome(String nome){
    this.nome = nome;
}

public String getEmail(){
    return email;
}

public void setEmail(String email){
    this.email = email;
}

public String getTelefone(){
    return telefone;
}

public void setTelefone(String telefone){
    this.telefone = telefone;
}

public String getCelular(){
    return celular;
}

public void setCelular(String celular){
    this.celular = celular;
}

public String getCurso(){
    return curso;
}

public void setCurso(String curso){
    this.curso = curso;
}

public String getSerie(){
    return serie;
}

public void setSerie(String serie){
    this.serie = serie;
}

public String getCampus(){
    return campus;
}

public void setCampus(String campus){
    this.campus = campus;
}

}


import org.hibernate.<em>;

import org.hibernate.cfg.Configuration;

import java.util.</em>;

/**

*
  • @author  Paulo
    
    */
    
    public class AlunoDAO {
    
    // Atributos da Classe
    
    private org.hibernate.SessionFactory factory;
    
    /** Creates a new instance of AlunoDAO */
    
    public AlunoDAO() throws HibernateException{
    
    Configuration cfg = new Configuration();
    
    cfg.addResource(Aluno.hbm.xml);
    
    cfg.addClass(Aluno.class);
    
    factory = cfg.buildSessionFactory();
    

    }

    public void Insert(Aluno aluno)throws Exception{
    
    Session session = factory.openSession();
    
    session.save(aluno);
    
    session.flush();
    
    session.close();
    
    }
    
    public java.util.List getList(String condicao) throws Exception{
    
    Session session = factory.openSession();
    
    List alunos = null;
    
    session.flush();
    
    session.close();
    
    return(alunos);
    
    }
    
    public Aluno retrieve(String pk)throws Exception{
    
    Session session = factory.openSession();
    
    Aluno aluno = (Aluno)session.load(Aluno.class,pk);
    
    session.flush();
    
    session.close();
    
    return aluno;
    
    }
    
    public void delete(Aluno aluno) throws Exception{
    
    Session session = factory.openSession();
    
    session.delete(aluno);
    
    session.flush();
    
    session.close();
    
    }
    
    }
    

XML

<?xml version="1.0"?>
Tela de Cadastro no Netbeans

public class jfrmCadAlunos extends javax.swing.JFrame {

Aluno aluno = new Aluno();

AlunoDAO dao = new AlunoDAO();
/** Creates new form jfrmCadAlunos */
public jfrmCadAlunos() {
    initComponents();
}

/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    fieldRA = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    fieldNome = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    fieldEmail = new javax.swing.JTextField();
    jLabel4 = new javax.swing.JLabel();
    fieldTelefone = new javax.swing.JTextField();
    jLabel5 = new javax.swing.JLabel();
    fieldCelular = new javax.swing.JTextField();
    jLabel6 = new javax.swing.JLabel();
    fieldCurso = new javax.swing.JComboBox();
    jLabel7 = new javax.swing.JLabel();
    fieldSerie = new javax.swing.JTextField();
    jLabel8 = new javax.swing.JLabel();
    fieldCampus = new javax.swing.JComboBox();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jButton4 = new javax.swing.JButton();
    jButton5 = new javax.swing.JButton();

    setTitle("Alunos");
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            exitForm(evt);
        }
    });

    jPanel1.setLayout(new java.awt.GridBagLayout());

    jPanel1.setBorder(new javax.swing.border.TitledBorder("Dados do Aluno"));
    jLabel1.setText("Reg. Acad\u00eamico");
    jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(jLabel1, gridBagConstraints);

    fieldRA.setColumns(5);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(fieldRA, gridBagConstraints);

    jLabel2.setText("Nome");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(jLabel2, gridBagConstraints);

    fieldNome.setColumns(30);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(fieldNome, gridBagConstraints);

    jLabel3.setText("E-mail");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(jLabel3, gridBagConstraints);

    fieldEmail.setColumns(25);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(fieldEmail, gridBagConstraints);

    jLabel4.setText("Telefone");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(jLabel4, gridBagConstraints);

    fieldTelefone.setColumns(11);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(fieldTelefone, gridBagConstraints);

    jLabel5.setText("Celular");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(jLabel5, gridBagConstraints);

    fieldCelular.setColumns(11);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(fieldCelular, gridBagConstraints);

    jLabel6.setText("Curso");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(jLabel6, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(fieldCurso, gridBagConstraints);

    jLabel7.setText("S\u00e9rie");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(jLabel7, gridBagConstraints);

    fieldSerie.setColumns(1);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(fieldSerie, gridBagConstraints);

    jLabel8.setText("Campus");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(jLabel8, gridBagConstraints);

    fieldCampus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cascavel", "Cianorte", "Francisco Beltrão", "Guaíra", "Paranavaí", "Toledo", "Umuarama" }));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel1.add(fieldCampus, gridBagConstraints);

    jButton1.setIcon(new javax.swing.ImageIcon("D:\\instalar\\icons\\XP Pack Sample\\GIFs\\32X32\\adreess-book.gif"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new java.awt.Insets(0, 13, 0, 13);
    jPanel1.add(jButton1, gridBagConstraints);

    jButton2.setIcon(new javax.swing.ImageIcon("D:\\instalar\\icons\\XP Pack Sample\\GIFs\\32X32\\adreess-book.gif"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new java.awt.Insets(0, 13, 0, 13);
    jPanel1.add(jButton2, gridBagConstraints);

    jButton3.setIcon(new javax.swing.ImageIcon("D:\\instalar\\icons\\XP Pack Sample\\GIFs\\32X32\\adreess-book.gif"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new java.awt.Insets(0, 13, 0, 13);
    jPanel1.add(jButton3, gridBagConstraints);

    jButton4.setIcon(new javax.swing.ImageIcon("D:\\instalar\\icons\\XP Pack Sample\\GIFs\\32X32\\adreess-book.gif"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new java.awt.Insets(0, 13, 0, 13);
    jPanel1.add(jButton4, gridBagConstraints);

    jButton5.setIcon(new javax.swing.ImageIcon("D:\\instalar\\icons\\XP Pack Sample\\GIFs\\32X32\\adreess-book.gif"));
    jButton5.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton5ActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new java.awt.Insets(5, 13, 5, 13);
    jPanel1.add(jButton5, gridBagConstraints);

    getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-462)/2, (screenSize.height-324)/2, 462, 324);
}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
    // Cadastra Aluno
    aluno.setRA(31532);
    aluno.setNome("Paulo Henrique Peres");
    aluno.setEmail("[email removido]");
    aluno.setTelefone("[telefone removido]");
    aluno.setCelular("[telefone removido]");
    aluno.setCurso("Sistemas de Informação");
    aluno.setSerie("1");
    aluno.setCampus("Umuarama");
    try{
        dao.Insert(aluno);
    } catch (Exception e){
        e.printStackTrace();
    }
}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
    dispose();
}

// Variables declaration - do not modify
private javax.swing.JComboBox fieldCampus;
private javax.swing.JTextField fieldCelular;
private javax.swing.JComboBox fieldCurso;
private javax.swing.JTextField fieldEmail;
private javax.swing.JTextField fieldNome;
private javax.swing.JTextField fieldRA;
private javax.swing.JTextField fieldSerie;
private javax.swing.JTextField fieldTelefone;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
// End of variables declaration

}

Porém quando vou rodar

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

at org.hibernate.cfg.Configuration.(Configuration.java:110)

at classes.AlunoDAO.(AlunoDAO.java:21)

at classes.jfrmCadAlunos.(jfrmCadAlunos.java:15)

at classes.jfrmPrincipal.jButton1ActionPerformed(jfrmPrincipal.java:100)

at classes.jfrmPrincipal.access$100(jfrmPrincipal.java:13)

at classes.jfrmPrincipal$2.actionPerformed(jfrmPrincipal.java:50)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Se alguém puder ajudar

Valeu
Paulo

7 Respostas

_fs

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

Falta colocar o commons-logging.jar no classpath da sua aplicação.,

pauloperes

Kra fiz o q vc falou, porém ele fala que não consegue achar os arquivos hibernate.properties e Aluno,hbm.xml, eles estão na mesma pasta do projeto que estou fazendo, como não tava dando certo fiz isto:

import org.hibernate.<em>;

import org.hibernate.cfg.Configuration;

import java.util.</em>;

/**

*
  • @author  Paulo
    
    */
    
    public class AlunoDAO {
    
    // Atributos da Classe
    
    private org.hibernate.SessionFactory factory;
    
    /** Creates a new instance of AlunoDAO */
    
    public AlunoDAO() throws HibernateException{
    
    String driver   = org.postgresql.Driver;
    
    String url      = jdbc/:postgresql/://localhost/lagg_aluno”;
    
    String user     = Paulo;
    
    String senha    = “”;
    
    String min_size = 5;
    
    String max_size = 0;
    
    String time_out = 1800;
    
    String max_st   = 50;
    
    String dialect  = org.hibernate.dialect.PostgreSQLDialect;
    
    Properties propriedades = new Properties();
    
    propriedades.setProperty(hibernate.connection.driver, driver);
    
    propriedades.setProperty(hibernate.connection.url, url);
    
    propriedades.setProperty(hibernate.connection.username, user);
    
    propriedades.setProperty(hibernate.connection.password,senha);
    
    propriedades.setProperty(hibernate.c3p0.min_size, min_size);
    
    propriedades.setProperty(hibernate.c3p0.max_size, max_size);
    
    propriedades.setProperty(hibernate.c3p0.timeout, time_out);
    
    propriedades.setProperty(hibernate.c3p0.max_statements, max_st);
    
    propriedades.setProperty(hibernate.dialect, dialect);
    
    Configuration cfg = new Configuration();
    
    cfg.setProperties(propriedades);
    
    cfg.addClass(Aluno.class);
    
    factory = cfg.buildSessionFactory();
    

    }

    public void Insert(Aluno aluno)throws Exception{
    
    Session session = factory.openSession();
    
    session.save(aluno);
    
    session.flush();
    
    session.close();
    
    }
    
    public java.util.List getList(String condicao) throws Exception{
    
    Session session = factory.openSession();
    
    List alunos = null;
    
    session.flush();
    
    session.close();
    
    return(alunos);
    
    }
    
    public Aluno retrieve(String pk)throws Exception{
    
    Session session = factory.openSession();
    
    Aluno aluno = (Aluno)session.load(Aluno.class,pk);
    
    session.flush();
    
    session.close();
    
    return aluno;
    
    }
    
    public void delete(Aluno aluno) throws Exception{
    
    Session session = factory.openSession();
    
    session.delete(aluno);
    
    session.flush();
    
    session.close();
    
    }
    
    }
    

E veja o erro que continua aparecento

02/03/2005 11:44:00 org.hibernate.cfg.Environment 

INFO: Hibernate 3.0rc1

02/03/2005 11:44:00 org.hibernate.cfg.Environment 

INFO: hibernate.properties not found

02/03/2005 11:44:00 org.hibernate.cfg.Environment 

INFO: using CGLIB reflection optimizer

02/03/2005 11:44:00 org.hibernate.cfg.Environment 

INFO: using JDK 1.4 java.sql.Timestamp handling

02/03/2005 11:44:00 org.hibernate.cfg.Configuration addClass

INFO: Mapping resource: classes/Aluno.hbm.xml

org.hibernate.MappingException: Resource: classes/Aluno.hbm.xml not found

at org.hibernate.cfg.Configuration.addClass(Configuration.java:461)

at classes.AlunoDAO.(AlunoDAO.java:42)

at classes.jfrmCadAlunos.(jfrmCadAlunos.java:15)

at classes.jfrmPrincipal.jButton1ActionPerformed(jfrmPrincipal.java:100)

at classes.jfrmPrincipal.access$100(jfrmPrincipal.java:13)

at classes.jfrmPrincipal$2.actionPerformed(jfrmPrincipal.java:50)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Valeui

Paulo

_fs

Antes de mais nada, quando for posta código, coloque-o entre as tags [ code]seucodigo[ /code], assim ele fica endentado.

Como você declarou a classe Aluno no hibernate.cfg.xml (que deve estar dentro do diretório WEB-INF/classes)? Assim?

&lt;mapping resource="Aluno.hbm.xml" /&gt;
pauloperes

Lipe, valeu por enquanto kra.

Seguinte naum entendi.

Veja, devo tenho seguintes arquivos:

Aluno.class
AlunoDAO.class
Aluno.hbm.xml

Este arquivo que você falou (hibernate.cfg.xml) eu naum tenho ele.

Eu li um artigo no GUJ para usar o hibernate, porém la a versao do hibernate é 1.xx e a q to usando é a 3.

Ja sei que tem algumas diferenças.

Tipo, vc num tem ai uma receita de bolo para usar o hibernate.

Valeu

Paulo

_fs

imagino que você esteja usando o arquivo hibernate.properties para configura-lo, certo?

Adicione um arquivo chamado hibernate.cfg.xml na pasta WEB-INF/classes, o conteudo deste arquivo é o seguinte:

<?xml version="1.0"?>
&lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
	"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"&gt;

&lt;hibernate-configuration&gt;
	&lt;session-factory&gt;
		&lt;mapping resource="meu/pacote/Aluno.hbm.xml" /&gt;
	&lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;

E, a cada classe nova a ser persistida, adicione mais um elemento <mapping> neste arquivo, indicando o pacote corretamente.

pauloperes

Lipe,

Não tenho esta pasta, esotu no netbenas, só tenho o meu diretório com as classesm, tenho sim o hibernate.properties na própria pasta, porém na hora de rodar, da pau dizendo que naum acha o arquivo.

Vc, ja deve estar sem paciência (hehe)
Valeu
Paulo

_fs

Não estou sem paciência não :smiley:

Bem cara, não manjo de netbeans, porém, se a IDE está te atrapalhando … tire ela do caminho e crie as pastas na mão oras.

Criado 2 de março de 2005
Ultima resposta 2 de mar. de 2005
Respostas 7
Participantes 2