Erro na inserção Hibernate!

4 respostas
Z

Ola amigos ! estou aprendendo Hibernate e não consigo resolver o seguinte problema

erro na inserção:org.hibernate.mappingnotfoundexception:resource:cores.hbm.xml not found
31 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
31 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
47 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
47 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
172 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
172 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
359 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : cores.hbm.xml

Abaixo os codigos !!

<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : hibernate.cfg.xml
    Created on : 22 de Setembro de 2009, 09:06
    Author     : danilo
    Description:
        Purpose of the document follows.
-->

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0/EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name ="cores" table="_m_cad_cores">
        <id>
            name ="cod"
        </id>
        <property name ="cor" />
        <property name ="numero_cor" />
    </class>
</hibernate-mapping>
package classes_cores;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author danilo
 */
public class cores {
    private int cod;
    private String cor;
    private int numero_cor;

    public cores(){
    }

    public int getCod() {
        return cod;
    }
    public void setCod(int cod) {
        this.cod = cod;
    }

    public String getCor() {
        return cor;
    }
    public void setCor(String cor) {
        this.cor = cor;
    }

    public int getNumero_cor() {
        return numero_cor;
    }
    public void setNumero_cor(int numero_cor) {
        this.numero_cor = numero_cor;
    }

    
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package classes_cores;
import javax.swing.JOptionPane;
import org.hibernate.*;
import org.hibernate.cfg.*;

/**
 *
 * @author danilo
 */
public class persiste_cores {

   // public persiste_cores(){

   // }

    public static void main(String [] args){
        try
        {
            SessionFactory fabrica = new Configuration().configure().buildSessionFactory();
            Session sessao = fabrica.openSession();
            cores Cores = new cores();
            Cores.setCod(1);
            Cores.setCor("AZULLLAO");
            Cores.setCod(999);
            Transaction tx_cores = sessao.beginTransaction();
            sessao.save(Cores);
            tx_cores.commit();
            sessao.clear();
        }
        catch(Exception erro){
            JOptionPane.showMessageDialog(null, "Erro na insersão:" + erro);
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : hibernate.cfg.xml
    Created on : 22 de Setembro de 2009, 08:39
    Author     : danilo
    Description:
        Purpose of the document follows.
-->

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0/EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">
            com.mysql.jdbc.Driver
        </property>
        <property name="hibernate.connection.url">
            jdbc:mysql://localhost:3306/movedb
        </property>
        <property name="hibernate.connection.username">
            root
        </property>
        <property name="hibernate.connection.password">
            root
        </property>
        <property name="hibernate.dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <mapping resource="cores.hbm.xml"/>
     </session-factory>
</hibernate-configuration>

Porque acontece isto?

mto obrigado

4 Respostas

R

O arquivo de mapeamento cores.hbm.xml está na mesma pasta que a classe classes_cores.cores? Nesse caso, acho que seu arquivo de configuração hibernate.cfg.xml deveria conter o trecho abaixo:

<mapping resource="/classes_cores/cores.hbm.xml"/>
Z

ainda aparece o mesmo erro quando faço esta modificação =/

Z

realmente o erro acontece ali… pois esta em pacote diferente

Mas alguem sabe como corrigir?

Z

coloquei tudo na mesma pasta “pacote padrão” e o seguinte erro aparece:

Erro na inseção:org.hibernate.InvalidMappingException:Could not parse mapping document from resource cores.hbm.xml

=|

Criado 22 de setembro de 2009
Ultima resposta 23 de set. de 2009
Respostas 4
Participantes 2