views:

45

answers:

1

I have an object mapped as follows:

<class name="A" table="TableA">
    <id name="ID" column="AId" type="Int32" unsaved-value="0">
        <generator class="native" />
    </id>
    <discriminator column="Type" type="Int32" />
    <property name="Description" />
</class>

<subclass name="B" discriminator-value="0" extends="A">
    <property name="B_specific_properties />
</subclass>

<subclass name="C" discriminator-value="1" extends="A">
    <property name="C_specific_properties />
</subclass>

I'm planning to use a stored procedure to do the insert, and currently both B and C uses the same stored procedure to insert into the table. My question is with the objects mapped as above, does the sql-insert belong to class A? If it does, is it expecting to do a save() on object A? How can I make it recognize the additional properties of B and C when I'm saving?

OR

Is using one stored procedure to save for the two sub-classes an impossible task, although they belong to the same table?

Thank you very much for any input!

A: 

I will show you how I did this

<class name="CompanyCharacteristic" table="firma_cecha" abstract="true" discriminator-value="not null">
    <id name="Id" column="id_firma_cecha">
        <generator class="native" />
    </id>
    <discriminator column="typ_cechy"/>
    <property name="FriendlyTypeName" column="typ_cechy" insert="false" update="false"/>

    <property name="All" column="cecha_all" access="nosetter.camelcase"/>

    <!-- Auditing data -->
    <property name="UserInserted" access="nosetter.camelcase" column="user_insert" insert="true" update="false"/>
    <property name="DateInserted" column="data_insert" generated="insert" insert="false" update="false"/>

    <subclass discriminator-value="Akceptacja kart płatniczych" name="CreditCardAcceptanceCharacteristic">
        <property name="DoesIt" column="cecha_dec_1" not-null="true" type="DataAccess.NHibernate.Infrastructure.UserTypes.EnumValueInfoUserType`1[[Domain.Characteristics.YesNoNumericEnum, Domain]], DataAccess"/>
        <sql-insert>
            DECLARE @returned decimal(20,0)
            exec sp_FirmaCecha_Add
            @TypCechy = 'Akceptacja kart płatniczych',
            @CechaAll = ?,
            @UserInsertZrodlo = ?,
            @CechaDec1 = ?,
            @IdFirmaCecha = @returned OUTPUT
            SELECT @returned
        </sql-insert>
        <sql-update>
            exec sp_FirmaCecha_Update
            @TypCechy = 'Akceptacja kart płatniczych',
            @UserUpdateZrodlo = ?,
            @CechaDec1 = ?,
            @IdFirmaCecha = ?
        </sql-update>
        <sql-delete>
            exec sp_FirmaCecha_Delete ?
        </sql-delete>
    </subclass>

    <sql-insert>
        raiserror ('CompanyInfoCharacteristic nie moze byc dodwana za pomocą NHibernate',11,1)
    </sql-insert>
    <sql-update>
        raiserror ('CompanyInfoCharacteristic nie moze byc aktualizowana za pomocą NHibernate.',11,1)
    </sql-update>
    <sql-delete>
        raiserror ('CompanyInfoCharacteristic nie moze byc kasowana za pomocą NHibernate.',11,1)
    </sql-delete>

As you can see every subclass need to have its own sql statements. Base class can have its own statements also. In this example I do not allow to modify Base class instances through NHibernate

rodpl
Thanks for your response. So I'm getting the sense that I will need to create two different stored procedures for object B and C, and if the number of properties are different in B and C, then the number of parameters passed to the stored procedure will be different as well?
Akey