claudete 26 de mar. de 2007
claudete 26 de mar. de 2007
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>
claudete 27 de mar. de 2007
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 );
}
}
}