Rodando um sisteminha que estou fazendo juntamente com hibernate, ele gera o erro abaixo:
18:58:15,656 INFO Environment:500 - Hibernate 3.2.1
18:58:15,671 INFO Environment:533 - hibernate.properties not found
18:58:15,671 INFO Environment:667 - Bytecode provider name : cglib
18:58:15,687 INFO Environment:584 - using JDK 1.4 java.sql.Timestamp handling
18:58:15,765 INFO Configuration:1423 - configuring from resource: /hibernate.cfg.xml
18:58:15,765 INFO Configuration:1400 - Configuration resource: /hibernate.cfg.xml
18:58:16,140 DEBUG DTDEntityResolver:38 - trying to resolve system-id [file:///C:/JAVA/Sistemao/hibernate-configuration-3.0.dtd]
18:58:16,250 DEBUG Configuration:1384 - hibernate.dialect=org.hibernate.dialect.MySQLDialect
18:58:16,250 DEBUG Configuration:1384 - hibernate.connection.driver_class=com.mysql.jdbc.Driver
18:58:16,250 DEBUG Configuration:1384 - hibernate.connection.url=jdbc:mysql://localhost/mysql
18:58:16,250 DEBUG Configuration:1384 - hibernate.connection.username=root
18:58:16,250 DEBUG Configuration:1384 - hibernate.connection.password=2000
18:58:16,250 DEBUG Configuration:1384 - hibernate.c3p0.max_size=10
18:58:16,250 DEBUG Configuration:1384 - hibernate.c3p0.min_size=2
18:58:16,250 DEBUG Configuration:1384 - hibernate.c3p0.timeout=5000
18:58:16,250 DEBUG Configuration:1384 - hibernate.c3p0.max_statements=10
18:58:16,250 DEBUG Configuration:1384 - hibernate.c3p0.idle_test_period=3000
18:58:16,250 DEBUG Configuration:1384 - hibernate.c3p0.acquire_increment=2
18:58:16,250 DEBUG Configuration:1384 - show_sql=true
18:58:16,250 DEBUG Configuration:1384 - hibernate.generate_statistics=true
18:58:16,281 DEBUG Configuration:1384 - hibernate.use_sql_comments=true
18:58:16,281 DEBUG Configuration:1583 - null<-org.dom4j.tree.DefaultAttribute@73a34b [Attribute: name resource value "Usuario.hbm.xml"]
18:58:16,281 INFO Configuration:553 - Reading mappings from resource : Usuario.hbm.xml
18:58:16,281 DEBUG DTDEntityResolver:38 - trying to resolve system-id [file:///C:/JAVA/Sistemao/hibernate-mapping-3.0.dtd]
18:58:16,484 INFO HbmBinder:300 - Mapping class: Usuario -> usuario
org.hibernate.InvalidMappingException: Could not parse mapping document from resource Usuario.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1584)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1552)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1531)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1505)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at com.homedns.fgriep.Sistemao.HibernateUtility.<clinit>(HibernateUtility.java:24)
at com.homedns.fgriep.Sistemao.Teste.main(Teste.java:21)
Caused by: org.hibernate.MappingException: class Usuario not found while looking for property: usuario_id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:401)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:334)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 8 more
Caused by: java.lang.ClassNotFoundException: Usuario
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
... 16 more
Exception in thread "main" java.lang.NullPointerException
at com.homedns.fgriep.Sistemao.HibernateUtility.getSession(HibernateUtility.java:31)
at com.homedns.fgriep.Sistemao.Teste.main(Teste.java:21)
Pelo que entendi é que não existe a classe Usuario, mas ela está aqui:
/*
* Usuario.java
*
* Created on 2 de Dezembro de 2006, 17:01
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.homedns.fgriep.Sistemao;
/**
*
* @author Griep
*/
public class Usuario {
private Integer usuario_id;
private String login;
private String senha;
private String nome;
private Boolean ativado;
public Usuario(){
}
public Usuario( Integer usuario_id, String login, String senha, String nome, String ativado ) {
this.setUsuario_Id( usuario_id );
this.setLogin( login );
this.setSenha( senha );
this.setNome( nome );
this.setAtivado( ativado.equalsIgnoreCase( "S" ) );
}
public Integer getUsuario_id() {
return usuario_id;
}
public void setUsuario_Id(Integer usuario_id) {
this.usuario_id = usuario_id;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Boolean getAtivado() {
return ativado;
}
public void setAtivado(Boolean ativado) {
this.ativado = ativado;
}
}
E o seu rbm.xml aqui:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : Usuario.hmb.xml
Created on : 2 de Dezembro de 2006, 17:14
Author : Griep
Description:
Purpose of the document follows.
-->
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Usuario" table="usuario">
<id name="usuario_id">
<generator class="increment"/>
</id>
<property name="login"/>
<property name="senha"/>
<property name="nome"/>
<property name="nome" type="boolean"/>
</class>
</hibernate-mapping>
O utilitário do hibernate:
/*
* HibernateUtility.java
*
* Created on 2 de Dezembro de 2006, 17:59
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.homedns.fgriep.Sistemao;
/**
*
* @author Griep
*/
//Arquivo HibernateUtility.java
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;
public class HibernateUtility {
private static SessionFactory factory;
static {
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
factory = null;
}
}
public static Session getSession() {
return factory.openSession();
}
}
E a classe que tem o método main():
/*
* Teste.java
*
* Created on 2 de Dezembro de 2006, 18:01
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.homedns.fgriep.Sistemao;
import org.hibernate.Session;
import org.hibernate.Transaction;
/**
*
* @author Griep
*/
public class Teste {
public static void main(String[] args) {
Session sessao = HibernateUtility.getSession(); //Abrindo uma sessão
Transaction transaction = sessao.beginTransaction(); //Iniciando uma transação
Usuario usuario = new Usuario(); //Instanciando um objeto transiente
//Preenchendo as propriedades do objeto
usuario.setLogin("Griep");
usuario.setSenha("2000");
usuario.setNome("Felipe Griep");
sessao.save(usuario); //Transformando o objeto transiente em um objeto persistente no banco de dados
transaction.commit(); //Finalizando a transação
sessao.close(); //Fechando a sessão
}
}
O hibernate.cfg.xml que está aqui:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/mysql
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
2000
</property>
<!-- Condiguração do c3p0 -->
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- Configura├º├Áes de debug -->
<property name="show_sql">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping resource="Usuario.hbm.xml"/>
</session-factory>
</hibernate-configuration>
E finalmente a tabela no banco MySql:
mysql> describe usuario;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| usuario_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| login | varchar(20) | NO | | | |
| senha | varchar(20) | NO | | | |
| nome | varchar(50) | NO | | | |
| ativado | varchar(1) | YES | | NULL | |
+------------+------------------+------+-----+---------+----------------+
5 rows in set (0.39 sec)
O que deve estar gerando este erro??? Quem pode ajudar-me???
Obrigado!!!