Using NHibernate 1.2.0CR1 I am trying to use the table per class hierarchy inheritance mapping strategy. Because of our database structure I need to use a view to pull all of the necessary pieces together, which is why I placed the view name in for the table name.
I am able to retrieve data from the database but when I attempt to save new PropertyValue instances I get the following SQL exception:
Code:
View or function 'VW_PROPERTYVALUE' is not updatable because the modification affects multiple base tables.
I've tried moving the <sql-insert> out of the subclass mapping and into the base class mapping with no effect. Should the <sql-insert> be honored by the <class> or <subclass> elements? Why is NHibernate trying to insert into the view?
Here is my mapping for this particular class:
Code:
<class name="PropertyValue" table="VW_PROPERTYVALUE">
<id name="Id" column="PROPERTYVALUE_PK" type="long" unsaved-value="-1">
<generator class="native">
<param name="sequence">SEQ_PK</param>
</generator>
</id>
<discriminator column="CLRTYPE" type="String" />
<many-to-one name="PropertyDefinition" class="PropertyDefinition" column="PROPERTYDEF_FK" lazy="false" />
<any name="Entity" meta-type="long" id-type="long">
<meta-value class="User" value="1" />
<column name="ENTITYTYPE_FK" />
<column name="ENTITY_FK" />
</any>
<subclass name="IntegerPropertyValue" extends="PropertyValue" discriminator-value="System.Int32">
<property name="Data" column="IntValue" type="int" />
<sql-insert>insert into TBL_PROPERTYVALUE (PROPERTYDEF_FK, ENTITY_FK, IntValue) VALUES (?, ?, ?)</sql-insert>
</subclass>
<subclass name="DateTimePropertyValue" discriminator-value="System.DateTime">
<property name="Data" column="DateTimeValue" type="DateTime" />
</subclass>
<subclass name="StringPropertyValue" discriminator-value="System.String">
<property name="Data" column="StringValue" type="string" />
</subclass>
</class>
Can anyone help?