title: Hibernate Unidirectional Parent/Child relationship - delete() performs update on child table instead of delete
body: <p><strong><em>If I delete a record from the Parent table I want the corresponding records in the child table to be deleted. How can I make Hibernate delete from the Child table rather than attempt to update with a null?</em></strong> </p>
  
  <p>I'm using Hibernate 3 but cannot use annotations at this time. I've attached copies of HBM, DAO etc below.  -- Thank you in Advance</p>
  
  <p>When attempting to delete data from tables in Parent/Child relationship I get the following error:</p>
  
  <pre><code>Testcase: testDelete(com.dressbarn.imbo.model.data.hibernate.dao.CharityTransferDAOTest):        Caused an ERROR
  Hibernate flushing: Could not execute JDBC batch update; uncategorized SQLException for SQL [update RMS12.DRS_CHARITY_TRANSFER_ITEM set TSF_NO=null, TSF_SEQ_NO=null where TSF_NO=?]; SQL state [72000]; error code [1407]; ORA-01407: cannot update ("RMS12"."DRS_CHARITY_TRANSFER_ITEM"."TSF_NO") to NULL
  ; nested exception is java.sql.BatchUpdateException: ORA-01407: cannot update ("RMS12"."DRS_CHARITY_TRANSFER_ITEM"."TSF_NO") to NULL
  
  org.springframework.jdbc.UncategorizedSQLException: Hibernate flushing: Could not execute JDBC batch update; uncategorized SQLException for SQL [update RMS12.DRS_CHARITY_TRANSFER_ITEM set TSF_NO=null, TSF_SEQ_NO=null where TSF_NO=?]; SQL state [72000]; error code [1407]; ORA-01407: cannot update ("RMS12"."DRS_CHARITY_TRANSFER_ITEM"."TSF_NO") to NULL
  ; nested exception is java.sql.BatchUpdateException: ORA-01407: cannot update ("RMS12"."DRS_CHARITY_TRANSFER_ITEM"."TSF_NO") to NULL
  
  Caused by: java.sql.BatchUpdateException: ORA-01407: cannot update ("RMS12"."DRS_CHARITY_TRANSFER_ITEM"."TSF_NO") to NULL
  
          at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:498)
          at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:12368)
          at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
          at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
          at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
          at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
          at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
          at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
          at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
          at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:578)
          at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662)
          at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314)
          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
          at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:629)
          at com.dressbarn.imbo.model.data.hibernate.dao.CharityTransferDAO$$EnhancerByCGLIB$$6a21cd58.delete(&lt;generated&gt;)
          at com.dressbarn.imbo.model.data.hibernate.dao.CharityTransferDAOTest.testDelete(CharityTransferDAOTest.java:112)
          at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
  </code></pre>
  
  <p>My tables are:</p>
  
  <p><strong>Parent</strong>:</p>
  
  <pre><code>CREATE TABLE DRS_CHARITY_TRANSFER
  (
    TSF_NO          NUMBER(10)                    NOT NULL Primary Key,
    FROM_LOC        NUMBER(10),
    CHARITY_LOC_ID  NUMBER(10),
    STATUS          VARCHAR2(1 CHAR),
    CREATE_DATE     DATE,
    EXT_REF_NO      VARCHAR2(30 CHAR),
    COMMENT_DESC    VARCHAR2(2000 CHAR),
    USER_ID         VARCHAR2(30 CHAR)
  )
  </code></pre>
  
  <p><strong>Child:</strong></p>
  
  <pre><code>CREATE TABLE DRS_CHARITY_TRANSFER_ITEM
   (
    TSF_NO      NUMBER(10)  NOT NULL PRIMARY KEY,
    ITEM        VARCHAR2(25 BYTE)  NOT NULL PRIMARY KEY,
    TSF_SEQ_NO  INTEGER,
    TSF_QTY     INTEGER
  )
  </code></pre>
  
  <p><strong>HBM XML</strong></p>
  
  <pre><code>&lt;hibernate-mapping package="com.dressbarn.imbo.model.data.hibernate.transfer" schema="RMS12"&gt;
     &lt;class name="CharityTransfer" table="DRS_CHARITY_TRANSFER"&gt;
         &lt;id name="transferNumber" column="TSF_NO" unsaved-value="undefined"&gt;
  
         &lt;/id&gt;
         &lt;property column="FROM_LOC" length="10" name="fromLocation" type="java.lang.Long"/&gt;
         &lt;property column="CHARITY_LOC_ID" length="10" name="toCharityLocId" type="java.lang.Long"/&gt;
         &lt;property column="STATUS" name="status" type="string"/&gt;
         &lt;property column="EXT_REF_NO" name="documentNumber" type="string"/&gt;
         &lt;property column="COMMENT_DESC" name="comment" type="string"/&gt;
         &lt;property column="CREATE_DATE" name="createDate" type="string"/&gt;
         &lt;property column="USER_ID" name="userId" type="string"/&gt;
      &lt;list name="charityTransferItemList" cascade="all-delete-orphan" lazy="false"&gt;
          &lt;key column="TSF_NO" /&gt;
          &lt;list-index column="TSF_SEQ_NO"/&gt;
          &lt;one-to-many class="CharityTransferItem" /&gt;
      &lt;/list&gt;
  &lt;/class&gt;
  
  &lt;class name="CharityTransferItem" table="DRS_CHARITY_TRANSFER_ITEM"&gt;
      &lt;id name="item" column="TSF_NO" unsaved-value="undefined"&gt;
  
      &lt;/id&gt;
      &lt;property column="ITEM" name="item" type="string"/&gt;
      &lt;property column="TSF_SEQ_NO" length="10" name="sequence" type="integer"/&gt;
      &lt;property column="TSF_QTY" length="12" name="quantity" type="long"/&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p><strong>DAO</strong></p>
  
  <pre><code>public class CharityTransferDAO extends HibernateDaoSupport implements ICharityTransfer {
  
     public void delete(CharityTransfer charityTransfer) throws IMADataException {
         try {
           getSessionFactory()
                   .getCurrentSession()
                   .delete(charityTransfer);
        }
        catch (HibernateException e) {
          throw new IMADataException("failed to delete charity shipping information", e);
        }    
  }
  </code></pre>