-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problems deleting a collection
PostPosted: Mon Jun 26, 2006 9:43 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
I am having problems deleting a collection. This is the error message I get:

Code:
could not delete collection: [KBR.LAPD.DocumentManagement.Entities.Rfi.Transmittals#1258]
Source:NHibernate
StackTrace:   at NHibernate.Collection.AbstractCollectionPersister.Remove(Object id, ISessionImplementor session)
   at NHibernate.Impl.ScheduledCollectionRemove.Execute()
   at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
   at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
   at NHibernate.Impl.SessionImpl.Execute()
   at NHibernate.Impl.SessionImpl.Flush()


No other information as to what the problem was. (Pointless error message in that case, don't you think?)

However, I do think it might be due to the fact that I have the same objects appearing at multiple points in the object graph due to a mildly complex set of relationships.

Any guidance?




=============================================

FYI: code running:

Code:
       /// <summary>
        /// Deletes the specified RFI.
        /// </summary>
        /// <param name="rfiId"></param>
        public override void DeleteById (int rfiId)
        {
            //Navigate the object graph and delete all the required objects and associations
            Rfi rfiToDelete;
            try
            {
                //Get the current full RFI object graph
                rfiToDelete = GetByIdWithAll(rfiId);
               
                //Now delete all the transmittals
                if(rfiToDelete.Transmittals != null)
                {
                    if(rfiToDelete.Transmittals.Count > 0)
                    {
                        foreach (object o in rfiToDelete.Transmittals)
                        {
                            Transmittal xmtl = o as Transmittal;
                            if(xmtl != null)
                            {
                                //Clear out any TransmittalRecipients
                                if(xmtl.TransmittalRecipients != null)
                                {
                                    if(xmtl.TransmittalRecipients.Count > 0)
                                    {
                                        foreach (object recipient in xmtl.TransmittalRecipients)
                                        {
                                            TransmittalRecipient transmittalRecipient = o as TransmittalRecipient;
                                            if(transmittalRecipient != null)
                                            {
                                                localSession.Delete(transmittalRecipient);
                                            }
                                        }
                                    }
                                }
                                xmtl.TransmittalRecipients.Clear();
                               
                                //Now clear out all the documents
                                if(xmtl.Documents != null)
                                {
                                    foreach (object obj in xmtl.Documents)
                                    {
                                        Document document = obj as Document;
                                        if(document != null)
                                        {
                                            localSession.Delete(document);
                                        }
                                    }
                                   
                                    xmtl.Documents.Clear();
                                }
                            }
                            //Now delete the transmittal
                            localSession.Delete(xmtl);
                        }
                    }
                    rfiToDelete.Transmittals = null;
                }
               
                //Delete workflow tasks
               
                if(rfiToDelete.WorkflowTasks != null)
                {
                    if(rfiToDelete.WorkflowTasks.Count > 0)
                    {
                        foreach (object task in rfiToDelete.WorkflowTasks)
                        {
                            WorkflowTask workflowTask = task as WorkflowTask;
                            if(workflowTask != null)
                            {
                                localSession.Delete(workflowTask);
                            }
                        }
                    }
                }
               
               
               
                //Delete history?
                if(rfiToDelete.History != null)
                {
                    if(rfiToDelete.History.Count > 0 )
                    {
                        foreach (object o in rfiToDelete.History)
                        {
                            RfiAction entry = o as RfiAction;
                            if(entry != null)
                            {
                                localSession.Delete(entry);
                            }
                        }
                    }
                }
               
               
                //Delete documents
                if(rfiToDelete.Documents != null)
                {
                    if(rfiToDelete.Documents.Count > 0)
                    {
                        foreach (object o in rfiToDelete.Documents)
                        {
                            Document doc = o as Document;
                            if(doc != null)
                            {
                                localSession.Delete(doc);
                            }
                        }
                    }
                }
               
                //finally, delete our RFI
                localSession.Delete(rfiToDelete);
               
               
               
            }
            catch(Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, ExceptionPolicyName.DataAccessPolicy);
                if(rethrow)
                {
                    throw;
                }
            }
        }


Related mappings:


Code:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="KBR.LAPD.DocumentManagement.Entities">
  <class name="KBR.LAPD.DocumentManagement.Entities.Rfi, Entities" table="RFI">
    <id name="RfiID" column="RFI_ID">
      <generator class="sequence">
        <param name="sequence">RFI_RFI_ID_SEQ</param>
      </generator>
    </id>
    <version name="Version" column="VERSION"/>
    <property name="RfiName" column="RFI_NAME" />
    <property name="Description" column="RFI_DESC" />
    <property name="RfiStatusID" column="RFI_STATUS_ID" />
    <property name="TransmittalMethodCode" column="XMTL_MTHD_CODE" />
    <property name="InApprovalDate" column="INAPPROVAL_DATE"/>
    <property name="SubmittedDate" column ="SUBMITTED_DATE" />
    <property name="CreatedDate" column="CREATED_DATE" />
    <property name="ClosedDate" column="CLOSED_DATE" />
    <bag name="History" table="RFI_HISTORY" outer-join="true" fetch="join" lazy="false" cascade="all-delete-orphan" order-by="TIMESTAMP DESC" >
      <key column="RFI_ID"/>
      <one-to-many class="KBR.LAPD.DocumentManagement.Entities.RfiAction, Entities"/>     
    </bag>
    <many-to-one name ="PurchaseOrder" class="KBR.LAPD.DocumentManagement.Entities.PurchaseOrder, Entities" column="PURCHASE_ORDER_ID" />   
    <many-to-one name ="Originator" class="KBR.LAPD.DocumentManagement.Entities.User, Entities" column="ORIGINATOR_USER_ID" />
    <many-to-one name ="OwnerGroup" class="KBR.LAPD.DocumentManagement.Entities.Group, Entities" column="OWNER_GROUP_ID" />
    <many-to-one name="TransmittalType" class="KBR.LAPD.DocumentManagement.Entities.TransmittalType, Entities" column="XMTL_TYPE_ID" fetch="select"/>
    <many-to-one name="SubProject" class="KBR.LAPD.DocumentManagement.Entities.SubProject, Entities"  column="SUB_PROJ_ID" outer-join="false" fetch="select" />
    <bag name="Documents"  table="DOC" order-by="DOC_ID" outer-join="true" fetch="join" lazy="false">
      <key column="RFI_ID" />
      <one-to-many class="KBR.LAPD.DocumentManagement.Entities.Document, Entities" />     
    </bag>
    <bag name="Transmittals" outer-join="true" fetch="join" table="XMTL" lazy="true">
      <key column="RFI_ID" foreign-key="XMTL_ID" />
      <one-to-many class="KBR.LAPD.DocumentManagement.Entities.Transmittal, Entities"/>     
    </bag>
    <bag name="WorkflowTasks" table="TASK" fetch="join" order-by="EXEC_ORDER" outer-join="true">
      <key column="RFI_ID"/>
      <one-to-many class="KBR.LAPD.DocumentManagement.Entities.WorkflowTask, Entities"/>
    </bag>
   
</class>
 
</hibernate-mapping>






<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="KBR.LAPD.DocumentManagement.Entities">

  <class name="KBR.LAPD.DocumentManagement.Entities.Transmittal, Entities" table="XMTL">
    <id name="TransmittalID" column="XMTL_ID">
      <generator class="sequence">
        <param name="sequence">XMTL_XMTL_ID_SEQ</param>
      </generator>
    </id>
    <version name="Version" column="VERSION"/>
    <property name="Comment" column="NOTES" />
    <many-to-one name="Rfi" column="RFI_ID" class="KBR.LAPD.DocumentManagement.Entities.Rfi, Entities"/>
    <bag name="Documents" table="DOC" outer-join="true" fetch="join" lazy="false" >
      <key column="XMTL_ID"/>
      <one-to-many class="KBR.LAPD.DocumentManagement.Entities.Document, Entities"/>
    </bag>
    <bag name="TransmittalRecipients" table="XMTL_RECIPIENT" outer-join="true" fetch="join" lazy="false" inverse="true"  >
      <key column ="XMTL_ID"></key>
      <one-to-many class ="KBR.LAPD.DocumentManagement.Entities.TransmittalRecipient, Entities"/>
    </bag>

  </class>
</hibernate-mapping>



<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="KBR.LAPD.DocumentManagement.Entities">
  <class name="KBR.LAPD.DocumentManagement.Entities.TransmittalRecipient, Entities" table="XMTL_RECIPIENT">
    <id name="TransmittalRecipientID" column="XMTL_REC_ID">
      <generator class="sequence">
        <param name="sequence">XMTL_RECIPIENT_ID_SEQ</param>
      </generator>
    </id>
    <version name="Version" column="VERSION"/>
    <property name="TurnaroundDays" column="XMTL_TURNAROUND_TIME" />
    <property name="AutoGenerated" column="AUTO_GENERATED" type="Boolean"  />
    <many-to-one name="Transmittal" class="KBR.LAPD.DocumentManagement.Entities.Transmittal, Entities" column="XMTL_ID"  />
    <many-to-one name="RecipientGroup" class="KBR.LAPD.DocumentManagement.Entities.Group, Entities" column="XMTL_REC_GROUP_ID" />
    <many-to-one name="RecipientTransmittalPurpose" class="KBR.LAPD.DocumentManagement.Entities.RecipientTransmittalPurpose, Entities" column="RECIPIENT_XMTL_PURPOSE_ID" />
  </class>
</hibernate-mapping>




<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="KBR.LAPD.DocumentManagement.Entities.Document, Entities" table="DOC">
    <id name="DocumentID" column="DOC_ID">
      <generator class="sequence">
        <param name="sequence">DOC_DOC_ID_SEQ</param>
      </generator>
    </id>
    <version name="Version" column="VERSION"/>
    <property name="DocumentName" column="DOC_NAME" length="100" type="string"  />
    <property name="FileName" column="DOC_FILENAME" length ="300" type="string" />
    <property name="Title" column="DOC_TITLE" length="100" type="string" />
    <property name="StorageLocation" column="DOC_STORAGE_LOCATION" length="100"  type="string" />
    <property name="DocumentStorageID" column="DOC_STORAGE_ID" />
    <property name="Revision" column="DOC_REVISION" type="string" length="5" />
    <property name="RevisionDate" column="DOC_REV_DATE"/>
    <property name="DocumentIdentifierString" column="DOC_GUID" type="string" not-null="true" />
    <property name="IsValid" column="IS_VALID" type="boolean" not-null="true" />
    <property name="SheetNumber" column="DOC_SHEET_NUMBER" type="string" />
    <property name="ValidationErrorSummary"  column="VAL_ERR_SUMMARY" />
    <many-to-one name="DocumentType" column="DOC_TYPE_ID"/>
    <many-to-one name="DocumentSubType" column="DOC_SUB_TYPE_ID"/>
    <many-to-one name="Transmittal" column="XMTL_ID"/>
    <many-to-one name="Rfi" column="RFI_ID"/>
    <many-to-one name="DocumentOrganisation" column="DOC_ORG_ID" class="KBR.LAPD.DocumentManagement.Entities.Organisation, Entities"/>
    <many-to-one name="DocumentDiscipline" column="DOC_DISC_ID" class="KBR.LAPD.DocumentManagement.Entities.Discipline, Entities"/>

    <bag name="Attributes" fetch="join" lazy="false" outer-join="true" table="DOC_ATTR">
      <key column="DOC_ID" />
      <one-to-many class="KBR.LAPD.DocumentManagement.Entities.Attribute, Entities"/>
    </bag>

  </class>
</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 10:55 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
well i'm thinking that you really shouldn't be replacing the rfiToDelete.Transmittals collection with NULL. that sort of breaks the rule that you can't replace a collection with a collection (even though NULL is not a collection per se). instead you might want to try:

Code:
                            }
                            //Now delete the transmittal
                            localSession.Delete(xmtl);
                            rfiToDelete.Transmittals.Remove(xmtl);
                        }
                    }
                    // instead of this
                    //rfiToDelete.Transmittals = null;


-devon


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 4:18 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
I tried doing the rfi.TRansmittals.Clear() and it still fails


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