Hi!
i have the same problem. i'm trying to map 4 entities with typical relationships. one of these is a linktable. I'm working on hibernate 3 over a postgres 8 database.
I've configured the mapping for cascade="delete" in all of the "manytoone" tags and all the "set" tags. when hibernate generates the tables and contraints , the foreing key actions are configured with NO ACTION (delete or update).
When i tried to run a delete operation, the exception is the same (update or delete on "searchcriteriatype" violates foreign key constraint "fkf1081d07efe0a597" on "searchcriteria")....
i've tried changing the foreing key actions manually over the database, but that doesnt matter because hibernate re-generate the tables ..
I'm using session.delete in this attempt, but i tried with a hql query like as "delete...."
this is my mapping for "searchcriteriatype"
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 04-dic-2006 10:34:11 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="kernel.Searchcriteriatype" table="searchcriteriatype">
<id name="id" type="integer">
<column name="pknid" />
<generator class="sequence" ><param name="sequence">sq_searchcriteriatype</param></generator>
</id>
<property name="name" type="string">
<column name="tname" />
</property>
<set name="searchcriterias" inverse="true" cascade="delete">
<key>
<column name="fknsearchcriteriatypeid" />
</key>
<one-to-many class="kernel.Searchcriteria" />
</set>
</class>
</hibernate-mapping>
i'm using a Home class to make this actions, this is the class
Code:
/*
* Archivo: ResourceHome.java
* Hora de Creacion: 14:51:19
* Fecha de Creacion: 05-dic-2006
* Nombre del Proyecto: AVA20071_HistoriaDesarrolloEmpresarialColombiano
* Nombre del Paquete: kernel.home
* Año: 2006
*/
package kernel.home;
import java.util.Collection;
...
import kernel.util.SessionManager;
public class SearchCriteriaTypeHome implements GeneralHome
{
private static final long serialVersionUID = 1L;
private Session session;
public SearchCriteriaTypeHome()
{
this.session=SessionManager.getSessionInstance();
}
...
...
...
public void delete(Object vo)
{
Searchcriteriatype res=(Searchcriteriatype)vo;
Transaction tx = this.session.beginTransaction ( );
this.session.delete ( "kernel.Searchcriteriatype", res );
tx.commit ( );
}
}
that's the other mapping,
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 04-dic-2006 10:34:11 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="kernel.Searchcriteria" table="searchcriteria" >
<id name="id" type="integer">
<column name="pknid" />
<generator class="sequence" ><param name="sequence">sq_searchcriteria</param></generator>
</id>
<property name="name" type="string">
<column name="tname" />
</property>
<many-to-one name="searchcriteriatype" class="kernel.Searchcriteriatype" fetch="select" cascade="delete">
<column name="fknsearchcriteriatypeid" />
</many-to-one>
<set name="relResourceSearchcriterias" inverse="true" cascade="delete">
<key>
<column name="fknsearchcriteriaid" />
</key>
<one-to-many class="kernel.RelResourceSearchcriteria" />
</set>
</class>
</hibernate-mapping>