-->
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: Hibernate one to many 's delete
PostPosted: Wed Oct 15, 2003 5:05 am 
Newbie

Joined: Sat Sep 13, 2003 12:47 pm
Posts: 15
Code:
   <class name="cn.mBig.experience.vo.SuffererVO" table="EXM_SUFFERER">
      <id name="id" type="java.lang.Long" unsaved-value="0">
         <column name="ID" sql-type="INT(10)"/>
         <generator class="identity"/>
      </id>
      <property name="name">
         <column name="NAME" not-null="true" sql-type="VARCHAR(40)"/>
      </property>
      <property name="creationDate" type="timestamp" column="CREATIONDATE"/>
      <property name="description">
         <column name="DESCRIPTION" sql-type="VARCHAR(255)"/>
      </property>
      <many-to-one name="creationUser" class="cn.mBig.experience.vo.UserVO" cascade="none" insert="false" update="false">
         <column name="CREATION_USER_ID" sql-type="INT(10)"/>
      </many-to-one>
      <property type="java.lang.Long" name="creationUid">
         <column name="CREATION_USER_ID" sql-type="INT(10)"/>
      </property>

      <property type="java.lang.Byte" name="state">
         <column name="STATE" sql-type="TINYINT(1)"/>
      </property>
      <property type="java.lang.Byte" name="gender">
         <column name="GENDER" sql-type="TINYINT(1)"/>
      </property>
      <many-to-one name="application" class="cn.mBig.experience.vo.ApplicationVO" cascade="none" insert="false" update="false">
         <column name="APPLICATION_ID" sql-type="INT(10)"/>
      </many-to-one>
      <property type="java.lang.Long" name="applicationId">
         <column name="APPLICATION_ID" sql-type="INT(10)"/>
      </property>
      <property name="address">
         <column name="ADDRESS" sql-type="VARCHAR(50)"/>
      </property>
      <property name="idCard">
         <column name="ID_CARD" sql-type="VARCHAR(30)"/>
      </property>
      <property name="phone">
         <column name="PHONE" sql-type="VARCHAR(40)"/>
      </property>
      <property name="birthday" type="date" column="BIRTHDAY"/>
      <bag name="suits" lazy="true" table="EXM_SUFFERER_SUIT" cascade="save-update">
         <key>
            <column name="SUFFERER_ID" sql-type="INT(10)"/>
         </key>
         <many-to-many class="cn.mBig.experience.vo.SuitVO">
            <column name="SUIT_ID" sql-type="INT(10)"/>
         </many-to-many>
      </bag>
      <bag name="units" lazy="true" table="EXM_SUFFERER_UNIT" cascade="save-update">
         <key>
            <column name="SUFFERER_ID" sql-type="INT(10)"/>
         </key>
         <many-to-many class="cn.mBig.experience.vo.UnitVO">
            <column name="UNIT_ID" sql-type="INT(10)"/>
         </many-to-many>
      </bag>
      <bag name="Results" lazy="false" cascade="all">
         <key>
            <column name="SUFFERER_ID"/>
         </key>
         <one-to-many class="cn.mBig.experience.vo.result.InspectResultVO"/>
      </bag>
   </class>


Code:
   <class name="cn.mBig.experience.vo.result.InspectResultVO" table="EXM_INSPECT_RESULT">
       <composite-id>
         <key-property name="suffererId" type="java.lang.Long">
           <column name="SUFFERER_ID" not-null="true" sql-type="INT(10)"/>         
        </key-property>
        <key-property name="itemId" type="java.lang.Long">
            <column name="ITEM_ID" not-null="true" sql-type="INT(10)"/>
        </key-property>
      </composite-id>
      <property name="result" type="java.lang.String">
          <column name="RESULT" not-null="true" sql-type="VARCHAR(255)"/>
      </property>
   </class>



when i delete SuffererVO, i thought hibernate might run "delete from EXM_INSPECT_RESULT where SUFFERER_ID=?"

but hibernate out print sql:
Hibernate: delete from EXM_SUFFERER_SUIT where SUFFERER_ID=?
Hibernate: delete from EXM_SUFFERER_UNIT where SUFFERER_ID=?
Hibernate: update EXM_INSPECT_RESULT set SUFFERER_ID=null where SUFFERER_ID=?


2003-10-10 13:06:02 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
warning: SQL Error: 1062, SQLState: S1009
2003-10-10 13:06:02 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
fatal: Invalid argument value, message from server: "Duplicate entry '0-1' for key 1"
2003-10-10 13:06:02 net.sf.hibernate.JDBCException <init>
fatal: Could not synchronize database state with session
java.sql.BatchUpdateException: Invalid argument value, message from server: "Duplicate entry '0-1' for key 1"

why?
how to get my wish operat?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 8:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Looks like you have not implemented a "parent/child relationship" properly.


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.