Hibernate erro

6 respostas
C

pessoal,
alguém pode me ajudar a resolver este erro?

Exception in thread "main" java.lang.NoClassDefFoundError: estudo/amigoDAO

na hibernate.cfg.xml, coloquei:

<mapping resource="/Desenvolvimento/Estudo/src/estudo/amigo.hbm.xml"/>

e na amigo.hbm.xml:

<class name="/Desenvolvimento/Estudo/src/estudo/amigoDAO" table="amigo">

tomando por base o exemplo do tutorial do GUJ…

6 Respostas

cado

tenta colocar apenas

/estudo/amigo.hbm.xml

C

não deu…

cado

coloca teu hibernate.cfg.xml e teu amigo.hbm.xml ai.

C

meu hibernate.cfg.xml

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



com.mysql.jdbc.Driver
jdbc:mysql://localhost/testebd
root
suporte

1

org.hibernate.dialect.MySQLDialect

thread

org.hibernate.cache.NoCacheProvider

true

create


meu amigo.hbm.xml
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping.dtd">
<hibernate-mapping>
    <class name="/Desenvolvimento/Estudo/src/estudo/amigo" table="amigo">
        <id name="cod" column="cod" type="int">
            <generator class="assigned"/>
        </id>
        <property name="nome" type="string" />
        <property name="endereco" type="string"/>
        <property name="telefone" column="fone" type="string"/>
        
    </class>
</hibernate-mapping>
C
Este é o meu amigoDAO... pq ele dá este erro?
Exception in thread "main" java.lang.NoClassDefFoundError: estudo/amigoDAO
package Estudo;


import estudo.amigo;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author root
 */
public class amigoDAO {
    
    private SessionFactory factory;
    private Hibernate hibernate;
    
    /** Creates a new instance of amigoDAO */
    
    public amigoDAO() throws Exception {
         Configuration cfg = new Configuration();
         cfg.addClass(amigo.class);
         factory = cfg.buildSessionFactory();
         
     }
      
     public void insert(amigo friend) throws Exception {
         Session session = factory.openSession();
         session.save(friend);
         session.flush();
         session.close();
     }
     
   /*  public java.util.List getList(String condicao) throws Exception{
         Session session = factory.openSession();
         List amigos = session.find(condicao);
         session.flush();
         session.close();
         return amigos;
     }*/
     
     public amigo retrieve(String pk) throws Exception{
         Session session = factory.openSession();
         amigo friend = (amigo)session.load(amigo.class, pk);
         session.flush();
         session.close();
         return friend;
     }
     
     public void delete(amigo friend) throws Exception{
         Session session = factory.openSession();
         session.delete(friend);
         session.flush();
         session.close();
     }
     
     public static void main (String a[]) {
         amigo b = new amigo();
         b.setNome("teste");
         b.setEndereco("testeend");
               
         try {
            amigoDAO ad = new amigoDAO();
            ad.insert(b);
            System.out.println("..."+b.getEndereco());
         } catch (Exception e) {
            System.out.println(""+e);
            
         }
     }
        
}
cado
<?xml version="1.0" encoding="UTF-8"?>

<root>

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/testebd</property>
<property name="connection.username">root</property>
<property name="connection.password">suporte</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="/estudo/amigo.hbm.xml"/>
</session-factory>
</hibernate-configuration>

</root>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping.dtd">
<hibernate-mapping>
    <class name="/estudo/amigo" table="amigo">
        <id name="cod" column="cod" type="int">
            <generator class="assigned"/>
        </id>
        <property name="nome" type="string" />
        <property name="endereco" type="string"/>
        <property name="telefone" column="fone" type="string"/>
        
    </class>
</hibernate-mapping>

Tenta deixar como esta ai em cima. O problema é que vc esta mapeando com o caminho incorreto. Verifique direito o caminho do seu classpath e arrume se necessario. :wink:

Criado 26 de março de 2007
Ultima resposta 27 de mar. de 2007
Respostas 6
Participantes 2