views:

8

answers:

0

I have the following HBMs (the sample is purely fictional, so don't try to understand the business needs)

Class Document

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Document" discriminator-value="Document">
    <id name="Id" type="long">
      <generator class="native" />
    </id>
    <discriminator />
    <property name="IssueDate" />
  </class>
</hibernate-mapping>

Class Invoice

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <subclass name="Invoice" discriminator-value="Invoice" extends="Document">
    <join table="Document_Invoice">
      <key column="ParentId" foreign-key="FK_Invoice_Document" />
      <property name="TotalInvoiced" />
      <many-to-one name="Cutomer" column="CutomerId" foreign-key="FK_Invoices_Cutomer" />
    </join>
  </subclass>
</hibernate-mapping>

Class Order

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <subclass name="Order" discriminator-value="Order" extends="Document">
    <join table="Document_Order">
      <key column="ParentId" foreign-key="FK_Order_Document" />
      <property name="TotalOrdered" />
      <many-to-one name="Provider" column="ProviderId" foreign-key="FK_Orders_Provider" />
    </join>
  </subclass>
</hibernate-mapping>

Class Partner

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Partner" discriminator-value="Partner">
    <id name="Id" type="long">
      <generator class="native" />
    </id>
    <set name="Orders" table="Document_Order" inverse="true">
      <key column="ProviderId" foreign-key="FK_Orders_Provider" />
      <one-to-many class="Order" />
    </set>
    <set name="Invoices" table="Document_Invoice" inverse="true">
      <key column="CustomerId" foreign-key="FK_Invoices_Customer" />
      <one-to-many class="Invoice" />
    </set>
  </class>
</hibernate-mapping>

This creates the following table sctructure:

CREATE TABLE [dbo].[Document](
    [Id] [bigint] IDENTITY(1,1) NOT NULL,
    [class] [nvarchar](255) NOT NULL,
    [IssueDate] [datetime] NULL,
    [CustomerId] [bigint] NULL,
    [ProviderId] [bigint] NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
) ON [PRIMARY]

CREATE TABLE [dbo].[Document_Invoice](
    [ParentId] [bigint] NOT NULL,
    [TotalInvoiced] [decimal](19, 5) NULL,
    [CustomerId] [bigint] NULL,
PRIMARY KEY CLUSTERED ([ParentId] ASC)
) ON [PRIMARY]

CREATE TABLE [dbo].[Document_Order](
    [ParentId] [bigint] NOT NULL,
    [TotalOrdered] [decimal](19, 5) NULL,
    [ProviderId] [bigint] NULL,
PRIMARY KEY CLUSTERED ([ParentId] ASC)
) ON [PRIMARY]

CREATE TABLE [dbo].[Partner](
    [Id] [bigint] IDENTITY(1,1) NOT NULL,
    [class] [nvarchar](255) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
) ON [PRIMARY]

I omitted all FKs for clarity. The problem is the last two fields from [Document] table. They are not supposed to be there. When running NHibernate updates the fields from the child tabled, but when loading the sets mapped in Partner it reads from the parent table, where field are null. How can I get this to work properly?