I've got a weird problem:
NHibernate is issuing 'DELETE FROM' statements on my database even though I am merely retrieving a list of records (that I am not even accessing anymore now).

To provide some context, I am querying a series of "TreatmentPlan" entities, each of which references a "Diagnosis" entity (a simple n:1 relationship). Now any "Diagnosis" entity can be associated with any number of "Client" entities, but this relationship is only defined in my mapping (using access="noop").

Here's my query:

    var plans = Session.CreateCriteria<TreatmentPlan>()
        .SetFetchMode("Diagnosis", FetchMode.Join)
        .SetFirstResult(start)
        .SetMaxResults(maxCount)
        .SetResultTransformer(Transformers.DistinctRootEntity);
        .List<TreatmentPlan>()

plans = new List<TreatmentPlan>(); // Do NOT touch plans returned by NHibernate at all after this

The resulting SQL (captured via log4net):

    SELECT
        this_.Id as Id11_5_,
        [lots of other treatment plan properties],
        diagnosis2_.Id as Id0_0_,
        [lots of other diagnosis properties]
    FROM
        Treatments this_
left outer join Diagnoses diagnosis2_ on this_.DiagnosisId=diagnosis2_.Id
    WHERE
        (case when this_.SchemaId is null then 0 else 1 end)='1'
        limit ?p1, ?p2

    DELETE FROM ClientDiagnoses WHERE DiagnosisId = ?p0
    DELETE FROM ClientDiagnoses WHERE DiagnosisId = ?p0
    DELETE FROM ClientDiagnoses WHERE DiagnosisId = ?p0
    DELETE FROM ClientDiagnoses WHERE DiagnosisId = ?p0
-- 4 different records are being deleted, one for each 'DiagnosisId' occurring in the query before

What the heck is NHibernate doing there?
I have not touched the data (as you see above), and I could not if I wanted to because the relationship between "Diagnosis" entites and "Client" entities is not even exposed in the entity classes.

Thankful for any help,
-Markus-

--
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