Dear ladies and sirs.
I use NHibernate 2.1 beta2.
First the scenario:
My objects are divided into two parts - the stub and the stub complement. The idea is that when a collection of objects is required from the database, only the stubs are fetched. Once the user accesses a particular object and if the accessed field belongs to the stub complement part - then the respective stub complement is fetched from the database. There is more to it, but the rest is irrelevant for my question.
Although, the stub and the stub complement denote different parts of the same object we could not figure out how to express this separation in a single mapping, so there are two mappings - one for the stub part of the object and another - for the stub complement, which is implemented as a private object nested within the stub.
Two more notes:
- The stub complement part does not contain the version field, only the stub does. Changing any field, be it in the stub or the stub complement affects the single version field.
- Our client is unaware of DAL at all, meaning there are no NHibernate assemblies on the client side. Objects are communicated to the server side, where they are attached to an NHibernate session.
The question:
Because there are two mappings (and, I guess, just one version field), when a fully loaded object (i.e. the one with loaded stub complement part) is updated NHibernate generates two update statements, which usually go for the same table.
We have a problem with it. Is it possible to merge them into one update statement?
Thanks.
P.S.
Here is an example mapping file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="SampleProject.Entities.EntityA,SampleProject.Entities" lazy="false" table="EntityA" >
<id name="Id" column="Id" type="int" >
<generator class="native" />
</id>
<version name="m_lastChanged" access="field" column="LastChanged" generated="always" type="Byte[]"/>
<property name="Name" access="property" type="string"/>
<component name="ParentId" class="SampleProject.Entities.EntityId,SampleProject.Entities">
<property name="TypeAsDBValue" access="property" type="string" column="ParentType" />
<property name="IdAsDBValue" access="property" type="string" column="ParentId" not-null="false"/>
</component>
</class>
<class name="SampleProject.Entities.EntityA+StubComplement,SampleProject.Entities" table="EntityA" lazy="false" >
<id name="OwnerId" column="Id" type="int" >
<generator class="native"/>
</id>
<property name="Description" access="property" type="string"/>
</class>
</hibernate-mapping>