On 12/22/2011 2:11 PM, Markus Ewald wrote:
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
[...]
And here are my mappings:
<class name="TreatmentSchema" table="Treatments" discriminator-value="0">
<id name="Id" />
<discriminator formula="(case when SchemaId is null then 0 else 1 end)" />
<!-- Lots of other properties -->
</class>
<subclass name="TreatmentPlan" extends="TreatmentSchema"
discriminator-value="1">
<many-to-one name="Diagnosis" column="DiagnosisId" />
<property name="SchemaId" not-null="true" />
<!-- Lots of other properties -->
</subclass>
<class name="Diagnosis" table="Diagnoses">
<id name="Id" />
<!-- Lots of other properties -->
<set name="Clients" table="ClientDiagnoses" access="noop">
<key column="DiagnosisId" />
<many-to-many class="Client" column="ClientId" />
</set>
</class>
<class name="Client" table="Clients">
<id name="Id" />
<!-- Lots of other properties -->
<set name="Diagnoses" table="ClientDiagnoses" access="noop">
<key column="ClientId" />
<many-to-many class="Diagnosis" column="DiagnosisId" />
</set>
</class>
My entities are plain classes with virtual properties implementing
INotifyPropertyChanged.
-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.