-->
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.  [ 2 posts ] 
Author Message
 Post subject: Parent update problem in Parent-Child (with composite ids)
PostPosted: Wed May 18, 2005 9:33 am 
Newbie

Joined: Wed May 18, 2005 9:10 am
Posts: 1
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>

------------------------------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 10:15 am 
Newbie

Joined: Wed Jun 15, 2005 5:36 am
Posts: 1
Hi,
Can you really save a parent and it´s children by just saving the parent?
I ask this because the keys in the set definition reference the name of the keys as used by the compisite-id of a child instead of the Colum name.

So must

<set name="detaylar" cascade="all" lazy="true">
<key>
<column name="torbano" />
<column name="tahsiltar"/>
</key>
<one-to-many
class=
"org.appfuse.model.TTorbadetay"/>
</set>


not be
<set name="detaylar" cascade="all" lazy="true">
<key>
<column name="TORBANO" /> !!
<column name="TAHSILTAR"/> !!
</key>
<one-to-many
class=
"org.appfuse.model.TTorbadetay"/>
</set>


Just asking!

If it is correct you probably have to set the cascading style of the set to ´all´.
If your notation is correct please reply


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