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.  [ 6 posts ] 
Author Message
 Post subject: nested exception is org.hibernate.exception.ConstraintViolat
PostPosted: Wed Jul 21, 2010 4:54 pm 
Newbie

Joined: Wed Jul 21, 2010 4:32 pm
Posts: 4
hello everyone i'm workin with java desktop using frameworks hibernate, openswing and spring. i've done some modules and i am trying making one more module but i got the next problem: The resource 'could not insert: [com.sietei.erp.estacion.Controlador]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert. Some one could help me please, i am quite new using these frameworks


Top
 Profile  
 
 Post subject: Re: nested exception is org.hibernate.exception.ConstraintViolat
PostPosted: Thu Jul 22, 2010 5:09 am 
Beginner
Beginner

Joined: Tue Jun 30, 2009 7:05 am
Posts: 29
Location: Italy
Hi jvank
The exception you get means that you are violating a constraint of your DB (primary and foregin keys, not null constraint, ....).
In my experience, the first times you use Hibernate it's quite easy to save an entity that has a foreign key to another entity that is not yet persisted, so I would check this first.
If you can post the code and the mappings you are using I could give them a look.

Stefano


Top
 Profile  
 
 Post subject: Re: nested exception is org.hibernate.exception.ConstraintViolat
PostPosted: Thu Jul 22, 2010 11:44 am 
Newbie

Joined: Wed Jul 21, 2010 4:32 pm
Posts: 4
this is my hibernate xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="com.sietei.erp.estacion.Controlador" table="est_controlador">
<id column="codigo" name="codigo">
<generator class="increment"/>
</id>
<property column="nombre" name="nombre"/>
<property column="protocolo" name="protocolo"/>
<property column="servidor" name="servidor"/>
<property column="puerto" name="puerto"/>
<property column="estado" name="estado"/>
</class>
</hibernate-mapping>

this is the class i use in my DataBasepackage com.sietei.erp.estacion;

import com.sietei.erp.Entidad;

public class Controlador extends Entidad {

// Código definido para el controlador
private Integer codigo;
public Integer getCodigo() { return codigo; }
public void setCodigo(Integer codigo) { this.codigo = codigo; }

// Ej.: CEM Derby 1
private String nombre;
public String getNombre() { return nombre; }
public void setNombre(String nombre) { this.nombre = nombre; }

// Ej.: CEMXML
private String protocolo;
public String getProtocolo() { return protocolo; }
public void setProtocolo(String protocolo) { this.protocolo = protocolo; }

private String servidor;
public String getServidor() { return servidor; }
public void setServidor(String servidor) { this.servidor = servidor; }

private int puerto;
public int getPuerto() { return puerto; }
public void setPuerto(int puerto) { this.puerto = puerto; }

private String estado;
public String getEstado() { return estado; }
public void setEstado(String estado) { this.estado = estado; }

}
my daoContext xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/b ... ns-2.5.xsd">
<bean id="baseDAO" class="com.sietei.erp.BaseDAO" abstract="true">
<property name="sessionFactory" ref="erpSessionFactory"/>
</bean>
<!-- Centralización -->
<bean id="servidorDAO" class="com.sietei.erp.centralizacion.ServidorDAO" parent="baseDAO" />
<!-- Estacion: Controlador -->
<bean id="controladorDAO" class="com.sietei.erp.estacion.ControladorDAO" parent="baseDAO" />
</beans>
my dispatcherServlet-xml<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/b ... ns-2.5.xsd">

<bean id="hessianObjectReceiver" class="org.openswing.swing.util.server.DefaultObjectReceiver" />
<bean id="handlerMapping" class="com.sietei.erp.comunicacion.ServicioHandlerMapping">
<property name="objectReceiver" ref="hessianObjectReceiver" />
</bean>
<bean id="swingViewResolver" class="org.openswing.springframework.web.servlet.view.OpenSwingViewResolver">
<property name="objectReceiver" ref="hessianObjectReceiver" />
</bean>
<bean id="funcionMethodNameResolver" class="com.sietei.erp.comunicacion.FuncionMethodNameResolver"></bean>

<bean id="baseController" class="com.sietei.erp.BaseController" abstract="true">
<property name="methodNameResolver" ref="funcionMethodNameResolver" />
<property name="seguridadService" ref="seguridadService" />
</bean>

<bean id="configuracionController" class="com.sietei.erp.estacion.ConfiguracionController" parent="baseController">
<property name="estacionService" ref="estacionService" />
</bean>
</beans>


Top
 Profile  
 
 Post subject: Re: nested exception is org.hibernate.exception.ConstraintViolat
PostPosted: Thu Jul 22, 2010 11:49 am 
Newbie

Joined: Wed Jul 21, 2010 4:32 pm
Posts: 4
continue the structure of my project
my ormContext xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/b ... ns-2.5.xsd">
<bean id="erpDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="url" value="jdbc:mysql://localhost:3306/7iERP"/>
<property name="username" value="root"/>
<property name="password" value="mysql"/>
</bean>
<bean id="erpSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="dataSource" ref="erpDataSource"/>
<property name="mappingResources">
<list>
<value>com/sietei/erp/estacion/Configuracion.hbm.xml</value>
</list>
</property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
</entry>
</map>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
</value>
</property>
</bean>
</beans>
my serviceContext xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/b ... ns-2.5.xsd">
<!-- Centralización -->
<bean id="centralizacionService" class="com.sietei.erp.centralizacion.CentralizacionService">
<property name="servidorDAO" ref="servidorDAO" />
</bean>
<bean id="estacionService" class="com.sietei.erp.estacion.EstacionService">
<property name="controladorDAO" ref="controladorDAO"/>
</bean>
</beans>


Top
 Profile  
 
 Post subject: Re: nested exception is org.hibernate.exception.ConstraintViolat
PostPosted: Thu Jul 22, 2010 12:27 pm 
Newbie

Joined: Wed Jul 21, 2010 4:32 pm
Posts: 4
Thanks i found the problem that caused error in my project, it was in the interface because i call the same column from my database.
Thanks the Stefano for telling me about the keys.


Top
 Profile  
 
 Post subject: Re: nested exception is org.hibernate.exception.ConstraintViolat
PostPosted: Thu Feb 10, 2011 12:51 pm 
Newbie

Joined: Thu Feb 10, 2011 12:40 pm
Posts: 1
Hi jvank,

I am getting the same error in my application. what did you mean by your below response.
"it was in the interface because i call the same column from my database."

I've a one-one relationship defined from parent-to-child in hte parent mapping file. I have casecade="none" defined in ththis mapping file.

I am trying insert just the parent. all columns in the parent are defined as not-null. I've verified that all columnsin the parent are being set to value before the session.save(parent) is being called.

please let me know folks, if you could think of due to what the error could be.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.