Hibernate deleta registros da tabela quando tenta inserir registro

Pessoal !

Quando executo o método save() do hibernate ele apaga todos os registros da tabela e depois insere o registro que estou inserindo, ou seja, fica sempre cadastrado um único registro na tabela. Creio que seja alguma configuração no hibernate.cfg.xml, mas não encontro na net de jeito nenhum. Alguém já teve esse problema ?

Desde já agradeço.

Abçs

Tem como vc postar teu código? Deve ter alguma coisa errada em código.

Primeiramente gostaria de agradecer pela rápida resposta.

Os códigos são os seguintes:

Mais uma vez obrigado

====> hibernate.cfg.xml
<?xml version=‘1.0’ encoding=‘utf-8’?>
<!DOCTYPE hibernate-configuration PUBLIC “-//Hibernate/Hibernate Configuration DTD 3.0//EN” “http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>

<hibernate-configuration>

&lt;session-factory&gt;

    &lt;!-- Database connection settings --&gt;
    &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
    &lt;property name="connection.url"&gt;jdbc:postgresql://localhost:5432/basedados&lt;/property&gt;
    &lt;!--property name="connection.datasource"&gt;java:comp/env/jdbc/basedados&lt;/property--&gt;
    &lt;property name="connection.username"&gt;postgres&lt;/property&gt;
    &lt;property name="connection.password"&gt;postgres&lt;/property&gt;
    &lt;property name="connection.autocommit"&gt;true&lt;/property&gt;
    &lt;property name="show_sql"&gt;true&lt;/property&gt;
    &lt;property name="create-drop"&gt;false&lt;/property&gt;

    &lt;!-- JDBC connection pool (use the built-in) --&gt;
    &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;

    &lt;!-- SQL dialect --&gt;
    &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;
    &lt;!--property name="dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/property--&gt;

    &lt;!-- Enable Hibernate's automatic session context management --&gt;
    &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;

    &lt;!-- Disable the second-level cache  --&gt;
    &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;

    &lt;!-- Echo all executed SQL to stdout --&gt;
    &lt;property name="show_sql"&gt;true&lt;/property&gt;

    &lt;!-- Drop and re-create the database schema on startup --&gt;
    &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;

	&lt;!--mapping class="pacote.Usuario" /--&gt;
    &lt;mapping resource="pacote/Usuario.hbm.xml"/&gt;

&lt;/session-factory&gt;

</hibernate-configuration>

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

<hibernate-mapping>
<class name=“pacote.Usuario” table=“tb_usuario”>
<id name=“UsCod” column=“USCOD” type=“int”>
<generator class=“increment”/>
</id>
<property name=“UsSenha” column=“USSENHA” type=“string”/>
<property name=“UsNome” column=“USNOME” type=“string”/>
<property name=“UsEmail” column=“USEMAIL” type=“string”/>
</class>
</hibernate-mapping>

====> UsuarioDAO.java
package pacote;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

public class UsuarioDAO {

private SessionFactory factory;

public UsuarioDAO() throws Exception {
	factory = new Configuration().configure().buildSessionFactory();

}

public void UsInserir(Usuario us) throws Exception {
	Session session = factory.openSession();
	session.save(us);
	session.flush();
	session.close();
}

public void UsAlterar(Usuario us) throws Exception {
	Session session = factory.openSession();
	session.update(us);
	session.flush();
	session.close();
}

public void UsExcluir(Usuario us) throws Exception {
	Session session = factory.openSession();
	session.delete(us);
	session.flush();
	session.close();
}

public List getListaUsuario() {
	Session session = factory.openSession();
	String sql = &quot;from Usuario&quot;;

	List listaUsuarios = session.createQuery(sql).list();

	return listaUsuarios;
}

}

====> Usuario.java
package pacote;

public class Usuario {
private int usCod;

private String usSenha;

private String usNome;

private String usEmail;

public Usuario() {
}

public Usuario(String usSenha, String usNome, String usEmail) {
	this.setUsSenha(usSenha);
	this.setUsNome(usNome);
	this.setUsEmail(usEmail);
}

public String getUsEmail() {
	return usEmail;
}

public void setUsEmail(String usEmail) {
	this.usEmail = usEmail;
}

public String getUsNome() {
	return usNome;
}

public void setUsNome(String usNome) {
	this.usNome = usNome;
}

public String getUsSenha() {
	return usSenha;
}

public void setUsSenha(String usSenha) {
	this.usSenha = usSenha;
}

public int getUsCod() {
	return usCod;
}

public void setUsCod(int usCod) {
	this.usCod = usCod;
}

}

====> TesteHibernate.java
package pacote;

import java.util.List;

public class TesteHibernate {

public static void main(String[] args) throws Exception {

	try {
		String senha = &quot;abc&quot;;
		String nome = &quot;Nome&quot;;
		String email = &quot;email@email.com.br&quot;;

		UsuarioDAO dao = new UsuarioDAO();
		Usuario usuario = new Usuario(senha, nome, email);
		dao.UsInserir(usuario);
		System.out.println(&quot;Registro inserido com sucesso!!!&quot;);
		List lista = dao.getListaUsuario();
		for (int i = 0; i &lt; lista.size(); i++) {
			Usuario user = (Usuario)lista.get(i);
			System.out.println(user.getUsEmail());
		}
	} catch (Exception e) {
		System.out.println(&quot;Não foi possivel, Erro: &quot; + e.getMessage());
		e.printStackTrace();
	}
}

}

Olhe isso:

 <!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property> 

Ele sempre apaga o banco de dados anterior e cria um novo, por isso que nunca tem nada. Pra que ele não faça mais isso essa linha tem que ser removida.

Puuutz ! Que vacilo !
Muito obrigado a todos pelo help !
Grande abç