Hello,
I am using Spring + Hibernate + Struts.
My DB is IBM DB2 for OS/390 with driver:
class:com.ibm.db2.jcc.DB2Driver
I am trying to buid an application having insert/delete/update for both parent and child tables. I have implemented the application.
Everything is fine, i can see records of both parent and child. I can edit,
delete and update a child. but when it comes to update or delete a parent record (which has some childs) i get an error.
My child and parent tables use composite ids.
The Error, My Java Code and Hibernate files for parent and child are given below.
Thank you very much for your help.
The error is :
---------------------------Error ------------------------------------------------
javax.servlet.ServletException: (HibernateTemplate): data integrity violated by SQL 'null'; nested exception is com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -407, SQLSTATE: 23502, SQLERRMC: TORBANO
-----------------------------------------------------------------------------------
The Java code for removing a parent record is :
-----------------------Parent Code for removing parent node -----------------
public void removeTTorba(TTorbaKey torbakey) {
Object torba = getHibernateTemplate().load(TTorba.class,
torbakey);
getHibernateTemplate().delete(torba);
}
-----------------------------------------------------------------------------------
Hibernate files for Parent and Child tables are:
Torba.hbm.xml (Parent)
-----------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-
2.0.dtd">
<hibernate-mapping>
<class name="org.appfuse.model.TTorba" table="TCMBWEB.TTORBA">
<composite-id name="torbakey"
class="org.appfuse.model.TTorbaKey" unsaved-value="none">
<key-property name="torbano" column="TORBANO"
type="java.lang.Integer"/>
<key-property name="tahsiltar" column="TAHSILTAR"
type="java.sql.Date"/>
</composite-id>
<property name="kupurcesit" column="KUPURCESIT"
type="java.lang.Double" />
<property name="toptutar" column="TOPTUTAR"
type="java.lang.Double" />
<set name="detaylar" cascade="all" lazy="true">
<key>
<column name="torbano" />
<column name="tahsiltar"/>
</key>
<one-to-many
class=
"org.appfuse.model.TTorbadetay"/>
</set>
</class>
</hibernate-mapping>
-------------------------------------------------------------------------------------
TTorbaDetay Table (Child)
------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-
2.0.dtd">
<hibernate-mapping>
<class name="org.appfuse.model.TTorbadetay"
table="TCMBWEB.TTORBADETAY">
<composite-id name="detaykey"
class="org.appfuse.model.TTorbadetayKey" unsaved-
value="none">
<key-property name="bankakod" column="BANKAKOD"
type="java.lang.Integer"/>
<key-property name="tahsiltar" column="TAHSILTAR"
type="java.sql.Date"/>
<key-property name="to rbano" column="TORBANO"
type="java.lang.Integer"/>
</composite-id>
<property name="desteadet" column="DESTEADET"
type="java.lang.Integer" />
</class>
</hibernate-mapping>
------------------------------------------------------------------------------------
|