Hello,

I have an odd problem that most likely is due to mapping definitions,
but I don't know what the answer would be.  This is what I have:

1) I have a RptIngestGroup object with one or more RptDocumentBase
objects.

    public virtual IList<RptDocumentBase> RptDocumentBases { get;
set; }

  <!-- NOTE: the delete-orphan is needed to delete the base from the
group -->
   <bag table="ICEBERG.RPT_DOCUMENT_BASE" name="RptDocumentBases"
lazy="true" cascade="all,delete-orphan" inverse="true">
      <key foreign-key="rpt_document_base_fk"
column="ingest_group_id" />
      <one-to-many class="RptDocumentBase"/>
    </bag>

2) Each RptDocumentBase object has ONE RptDocumentCore objects:

    public virtual RptDocumentCore RptDocumentCore { get; set; }

   <many-to-one name="RptDocumentCore" column="DOC_CORE_ID"
cascade="all" />

3) Each RptDocumentCore object has one or more RptDocumentBase
objects:

    public virtual IList<RptDocumentBase> RptDocumentBases { get;
set; }

   <!-- NOTE: The cascade=all is needed to avoid an "unsaved
transient" exception -->
   <bag table="ICEBERG.RPT_DOCUMENT_BASE" name="RptDocumentBases"
lazy="true" cascade="all">
      <key foreign-key="rpt_document_base_fk2" column="doc_core_id" />
      <one-to-many class="RptDocumentBase"/>
    </bag>

The link between a RptDocumentCore record and a RptDocumentBase record
is that a "core" record represents a unique document.  A "base" record
has some metadata and points to a single "core" record.  This allows
for multiple "base" records to point to the same "core" record (to
avoid duplication).

My problem is that when I try to remove a RptDocumentBase object from
the RptIngestGroup object, ALL RptDocumentBase records with the same
RptDocumentCore reference as the "base" object I am deleting also get
deleted.  For example, I may have a RptIngestgroup object with 4
RptDocumentBase objects.  Three of those four "base" records point to
the same "core" record.  When I try to delete one of those objects
via:

   ingestGrp.RptDocumentBases.Remove(docBase); // in this case the
base id = 9052
   repository.Update(ingestGrp);  // this is a
session.Update(ingestGrp) call.

the result is that all three RptDocumentBase database records are
deleted.  The NHibernate SQL looks like:

NHibernate: UPDATE ICEBERG.RPT_DOCUMENT_BASE SET doc_core_id = null
WHERE doc_core_id = :p0;:p0 = 5642 [Type: Int64 (0)]
NHibernate: DELETE FROM ICEBERG.RPT_DOCUMENT_BASE WHERE DOC_BASE_ID
= :p0;:p0 = 9052 [Type: Int64 (0)]
NHibernate: DELETE FROM ICEBERG.RPT_DOCUMENT_BASE WHERE DOC_BASE_ID
= :p0;:p0 = 9062 [Type: Int64 (0)]
NHibernate: DELETE FROM ICEBERG.RPT_DOCUMENT_BASE WHERE DOC_BASE_ID
= :p0;:p0 = 9072 [Type: Int64 (0)]
NHibernate: DELETE FROM ICEBERG.RPT_DOCUMENT_CORE WHERE DOC_CORE_ID
= :p0;:p0 = 5642 [Type: Int64 (0)]

I don't know why the other database records are deleted but I have to
believe it is something with the NHibernate mapping files.  Does
anyone have any thoughts?

Thanks for any suggestions - Peter

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to