Hibernate ... problemas ... problemas!

Galera me ajuda aqui num negocio olha so eu to usando o hibernate 2 mas na hora de fazer uma inclussão ocorre o seguinte erro:

30/09/2003 11:39:24 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.0.3
30/09/2003 11:39:25 net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
30/09/2003 11:39:25 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
30/09/2003 11:39:25 net.sf.hibernate.cfg.Environment <clinit>
INFO: JVM proxy support: true
30/09/2003 11:39:25 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /resource/sicla.cfg.xml
30/09/2003 11:39:26 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: sic/sicla/dao/Usuario.hbm.xml
30/09/2003 11:39:35 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: sic.sicla.beans.Usuario -> TBUSUARIOS
30/09/2003 11:39:36 net.sf.hibernate.cfg.Configuration configure
INFO: Configured SessionFactory: null
30/09/2003 11:39:36 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
30/09/2003 11:39:36 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
30/09/2003 11:39:36 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
30/09/2003 11:39:36 net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.InterbaseDialect
30/09/2003 11:39:36 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 1
30/09/2003 11:39:36 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.firebirdsql.jdbc.FBDriver at URL: jdbc:firebirdsql:localhost/3050:c:/sic/sicla.gdb
30/09/2003 11:39:36 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sysdba, password=masterkey}
30/09/2003 11:39:36 net.sf.hibernate.ps.PreparedStatementCache <init>
INFO: prepared statement cache size: 25
30/09/2003 11:39:36 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use outer join fetching: true
30/09/2003 11:39:38 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use scrollable result sets: false
30/09/2003 11:39:38 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: echoing all SQL to stdout
30/09/2003 11:39:39 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: no JDNI name configured
30/09/2003 11:39:39 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Query language substitutions: {}
Hibernate: insert into TBUSUARIOS (NOME, SENHA, NIVEL, ID) values (?, ?, ?, ?)
java.lang.NullPointerException
30/09/2003 11:39:40 net.sf.hibernate.impl.SessionImpl finalize
WARNING: unclosed connection

Alguem pode me ajudar, dizendo oque esta acontecendo abaixo segue meu arquivo de mapeamento

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping.dtd">
<hibernate-mapping>
    <class name="sic.sicla.beans.Usuario" table="TBUSUARIOS">
        <id name="Id" column="ID" type="integer">
            <generator class="assigned"/>
        </id>
        <property name="Nome" column="NOME" type="string"/>
        <property name="Senha" column="SENHA" type="string"/>
        <property name="Nivel" column="NIVEL" type="string"/>
    </class>
</hibernate-mapping>

e esse e meu arquivo de configuração

<?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> 

      <!-- properties -->     
      <property name="dialect">net.sf.hibernate.dialect.InterbaseDialect</property> 
      <property name="connection.driver_class">org.firebirdsql.jdbc.FBDriver</property> 
      <property name="connection.url">jdbc:firebirdsql:localhost/3050:c:/sic/sicla.gdb</property> 
      <property name="connection.username">sysdba</property> 
      <property name="connection.password">masterkey</property> 

      <property name="connection.pool_size">1</property> 
      <property name="statement_cache.size">25</property> 

      <property name="show_sql">true</property> 
      <property name="use_outer_join">true</property> 

      <property name="jdbc.batch_size">0</property> 
      <property name="jdbc.use_streams_for_binary">true</property> 

      <property name="cglib.use_reflection_optimizer">false</property> 

        <!-- mapping files --> 
        <mapping resource="sic/sicla/dao/Usuario.hbm.xml"/> 
		
    </session-factory>
</hibernate-configuration>

Oque eu to fazendo de errado :frowning: da uma luz ai pessoal :roll:

aparentemente esta como eu faço também minhas configurações a diferença que eu nunca usei um arquivo de .xml de configuração do hibernate, ao invés disso, eu sempre usei o hibernate.properties e comigo funciona normal…

tenta criar um hibernate.properties e ve se funciona

Pude perceber que você está utilizando a versão 2.0 do hibernate, mas o arquivo de mapeamento não está. Tente trocar a seguinte linha:

[color=“blue”]“http://hibernate.sourceforge.net/hibernate-mapping.dtd”>[/color]

por esta aqui:

[color=“blue”]“http://hibernate.sourceforge.net/hibernate-mapping.dtd”>[/color]

e veja se o erro persiste.

oopss… desculpe pela falha… :oops:

troque pela seguinte linha:
[color=“blue”]
http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd”>
[/color]

Dá uma olha no http://www.guj.com.br/forum/viewtopic.php?t=5707 e veja como eu fiz… funcionou !!!

Galera e uma aplicação desktop essa que eu estou montando, ou seja nada de tomcat(web.xml e afins :lol: ) o problema esta acontecendo logo aqui

Hibernate: insert into TBUSUARIOS (NOME, SENHA, NIVEL, ID) values (?, ?, ?, ?)
java.lang.NullPointerException
30/09/2003 14:34:45 net.sf.hibernate.impl.SessionImpl finalize
WARNING: unclosed connection

eu recebo um java.lang.NullPointerException do nada sendo que todos dados do meu bean esta completo ??? ta dificil de resolver essa parada :? e outra coisa como faço para usar um arquivo de properties ao inves de um arquivo xml na configuração do hibernate ? onde eu passo ele ? :?:

to perdendo a paciencia :shock:

Outra coisa descobri que a porqueira do erro dá com qualquer banco testei Firebird,MySQL,Postgree mesma jaca será que vou ter de desistir do hibernate 2.03 a partir para outra versão !!! :cry:

Você ja se certificou que todos os dados estão realmente preenchidos? Inclusive o ID?
Passe o fragmento de código onde vc preenche os dados do bean para verificarmos. Pode estar ocorrendo algum problema ali.

Estou utilizando o hibernate sem problemas, enfrentei muitos no início com respeito ao mapeamento.

Não desista! Vale a pena!

ai vai o codigo da mina classe DAO e do meu bean galera !!!

Classe DAO:

package sic.sicla.dao;

/**
 * @author William J. Oliveira
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */

import java.util.Date;


import net.sf.hibernate.*;
import net.sf.hibernate.cfg.Configuration;

import sic.sicla.Resource;
import sic.sicla.beans.Usuario;

public class UsuarioDAO{

    private SessionFactory factory;
    private Transaction transaction;

    public UsuarioDAO() throws Exception{
        factory = new Configuration().configure("/resource/sicla.cfg.xml").buildSessionFactory();
        
    }
    
    public void insert(Usuario usuario) throws Exception{
        Session session = factory.openSession();
        session.save(usuario);
        session.flush();
        transaction.commit();
        session.close();
    }
    
    public java.util.List getList(String condicao) throws Exception{
        Session session = factory.openSession();
        java.util.List usuario = session.find(condicao);
        session.flush();
        session.close();
        return usuario;
    }
    
    public Usuario retrieve(String pk) throws Exception{
        Session session = factory.openSession();
        Usuario usuario = (Usuario)session.load(Usuario.class, pk);
        session.flush();
        session.close();
        return usuario;
    }
    
    public void delete(Usuario usuario) throws Exception{
        Session session = factory.openSession();
        session.delete(usuario);
        session.flush();
    	transaction.commit();    
        session.close();
    }
}

Classe Bean:

package sic.sicla.beans;

/**
 * @author William J. Oliveira
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class Usuario {
	private int id		=	0;
	private String nome	=	null;
	private String senha	=	null;
	private String nivel	=	null;



	public Usuario(){
	}
			
	/**
	 * Returns the id.
	 * @return int
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the nivel.
	 * @return String
	 */
	public String getNivel() {
		return nivel;
	}

	/**
	 * Returns the nome.
	 * @return String
	 */
	public String getNome() {
		return nome;
	}

	/**
	 * Returns the senha.
	 * @return String
	 */
	public String getSenha() {
		return senha;
	}

	/**
	 * Sets the id.
	 * @param id The id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the nivel.
	 * @param nivel The nivel to set
	 */
	public void setNivel(String nivel) {
		this.nivel = nivel;
	}

	/**
	 * Sets the nome.
	 * @param nome The nome to set
	 */
	public void setNome(String nome) {
		this.nome = nome;
	}

	/**
	 * Sets the senha.
	 * @param senha The senha to set
	 */
	public void setSenha(String senha) {
		this.senha = senha;
	}

}

Podem ver que são duas classes simples que eu to usando para ter base para classes mais complexas.Mas agarrei nessas já :oops:

public void insert(Usuario usuario) throws Exception{ Session session = factory.openSession(); session.save(usuario); session.flush(); transaction.commit(); session.close(); }

Já tentou

public void insert(Usuario usuario) throws Exception{ Session session = factory.openSession(); session.save(usuario); session.flush(); session.connection().commit(); session.close(); } ??