Aee galera espero que alguem possa me ajudar
seguinte na hora de gravar os dados da o seguinte erro
WARNING: SQL Error: 0, SQLState: 23502
org.hibernate.exception.ConstraintViolationException: could not insert: [HN.Cliente]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
Caused by: org.postgresql.util.PSQLException: ERRO: valor nulo na coluna "cod" viola a restri??o n?o-nula
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
Percebi que o codigo gerado do sql não recebeu os dados
naum aparece o campo cod no insert e os outros valores estao com ?
Hibernate: insert into tb_usuario (NOME, FONE, EMAIL) values (?, ?, ?)
13/02/2008 16:05:09 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
13/02/2008 16:05:09 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
13/02/2008 16:05:09 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
13/02/2008 16:05:09 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
vou postar meu codigo para ver se alguem sabe onde pode estar o erro
Cliente.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="HN.Cliente" table="tb_usuario">
<id name="cod" column="cod" type="java.lang.Integer">
<generator class="identity">
</generator>
</id>
<property name="nome" column="NOME" type="string"/>
<property name="fone" column="FONE" type="string"/>
<property name="email" column="EMAIL" type="string"/>
</class>
</hibernate-mapping>
hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.1.11:5432/CisterLabs</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password"> </property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<!-- Hibernate XML mapping files -->
<mapping resource="HN/Cliente.hbm.xml"/>
<!-- Hibernate Annotations (and package-info.java)
<mapping package="org.mypackage"/>
<mapping class="org.MyClass/>
-->
</session-factory>
</hibernate-configuration><!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.1.11:5432/CisterLabs</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password"> </property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<!-- Hibernate XML mapping files -->
<mapping resource="HN/Cliente.hbm.xml"/>
<!-- Hibernate Annotations (and package-info.java)
<mapping package="org.mypackage"/>
<mapping class="org.MyClass/>
-->
</session-factory>
</hibernate-configuration>
Cliente.java
public class Cliente
{
public int cod;
public String nome;
public String fone;
public String email;
/** Creates a new instance of Cliente */
public Cliente()
{
}
public int getCod() {
return cod;
}
public void setCod(int cod) {
this.cod = cod;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getFone() {
return fone;
}
public void setFone(String fone) {
this.fone = fone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
ClienteDAO.java
public class ClienteDAO {
private SessionFactory factory;
/** Creates a new instance of ClienteDAO */
public ClienteDAO()
{
factory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
}
public void inserir(Cliente cliente)
{
try
{
Session session = factory.openSession();
session.save(cliente);
session.flush();
session.close();
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public void alterar(Cliente cliente)
{
try
{
Session session = factory.openSession();
session.update(cliente);
session.flush();
session.close();
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public void excluir(Cliente cliente)
{
try
{
Session session = factory.openSession();
session.delete(cliente);
session.flush();
session.close();
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public Cliente buscar(Cliente cliente)
{
cliente = null;
try
{
Session session = factory.openSession();
cliente = (Cliente) session.get(Cliente.class, new Integer(1));
session.flush();
session.close();
}catch(Exception ex)
{
ex.printStackTrace();
}
return cliente;
}
}
Ajuda ae galera vlwww