-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Help - ClassNotFoundException
PostPosted: Tue Nov 30, 2004 7:05 am 
Newbie

Joined: Tue Nov 23, 2004 12:25 pm
Posts: 9
Please, i'm receiving this error but the class is in its place. Somebody help me?

net.sf.hibernate.MappingException: Error reading resource: HIBERNA_MYSQL/Amigo.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:339)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at HIBERNA_MYSQL.AmigoDAO.<init>(AmigoDAO.java:16)
at HIBERNA_MYSQL.TesteAmigo.main(TesteAmigo.java:15)
Caused by: net.sf.hibernate.MappingException: persistent class [Amigo] not found
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:84)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
... 6 more
Caused by: java.lang.ClassNotFoundException: Amigo
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:81)
... 11 more

----------------------------------------------------------------------------------
the hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="java:comp/env/hibernate/SessionFactory">


<!-- properties -->

<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">sa</property>
<property name="connection.password">sa</property>


<!-- mapping files -->
<mapping resource="HIBERNA_MYSQL/Amigo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
----------------------------------------------------------------
the class Amigo

package HIBERNA_MYSQL;

public class Amigo {
private String nome;
private String endereco;
private String telefone;
private String celular;
private String email;

public Amigo() {
}

public String getNome(){
return nome;
}

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

public String getEndereco(){
return endereco;
}

public void setEndereco(String endereco){
this.endereco = endereco;
}

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 getEmail(){
return email;
}

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

}

-----------------------------------------------------------------
the AmigoDao class:

package HIBERNA_MYSQL;
import java.util.List;

import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

public class AmigoDAO{

private SessionFactory factory;


public AmigoDAO() throws Exception{

//factory = new Configuration().addClass(Amigo.class).buildSessionFactory();
factory = new Configuration().configure().buildSessionFactory();;
//Session session = factory.openSession();
//java.sql.Connection cn = session.connection();

}

public void insert(Amigo amigo) throws Exception{
Session session = factory.openSession();
session.save(amigo);
session.flush();
session.close();
}

public java.util.List getList(String hql) throws Exception{
Session session = factory.openSession();
//List amigos = session.find(condicao);

List pessoas = session.find(hql);
for(int indice=0; indice<pessoas.size(); indice++)
{
Amigo amigo = (Amigo)pessoas.get(indice);

}
session.flush();
session.close();
return pessoas;
}

public Amigo retrieve(String pk) throws Exception{
Session session = factory.openSession();
Amigo amigo = (Amigo)session.load(Amigo.class, pk);
session.flush();
session.close();
return amigo;
}

public void delete(Amigo amigo) throws Exception{
Session session = factory.openSession();
session.delete(amigo);
session.flush();
session.close();
}
}

-----------------------------------------------------------------------------
the Amigo.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping.dtd">

<hibernate-mapping>
<class name="Amigo" table="amigos">
<id name="nome" column="nome" type="string">
<generator class="assigned"></generator>
</id>
<property name="endereco" column="endereco" type="string"/>
<property name="telefone" column="telefone" type="string"/>
<property name="celular" column="celular" type="string"/>
<property name="email" column="email" type="string"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 7:27 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
well ... i would take a look at the exception:
Code:
Caused by: java.lang.ClassNotFoundException: Amigo


the mapping file:
Code:
<class name="Amigo" table="amigos">


and your Amigo-Class
Code:
package HIBERNA_MYSQL;

public class Amigo { ....}


... you've simply forgotten the package ... ;)

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 8:49 am 
Newbie

Joined: Tue Nov 23, 2004 12:25 pm
Posts: 9
Great, curio! Its everything ok now. Thank you very much and excuse my attention fault. Whats the way to vote and increase your ranking?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 8:53 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
no problem, but thanx :)

i know those situations very well ... ;)

gtx
curio


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.