I have the following problem scenario:
A super class "Resource" with three subclasses - "SubContractor", "ResourceMonthlyEmployee", "ResourceHourlyEmployee".
Creating new resources is no problem but the problem comes when I want to change an existing resource from say a "ResourceMonthlyEmployee" to a "SubContractor".
This becomes a problem because of the way it is implemented. In the database the different classes are differentiated via a resource_type column with three different possible values: 1,2 and 3.
The hibernate mapping is specified as follows:
Code:
<class name="Resource.Resource,Business" table="Resource">
<id column="resource_id" type="System.Guid" name="Id">
<generator class="guid" />
</id>
<discriminator type="System.String" column="resource_type" insert="true"/>
<property name="FirstName" column="resource_first_name" type="System.String" />
<property name="LastName" column="resource_last_name" type="System.String" />
<property name="Pno" column="resource_pno" type="System.String" />
<subclass dynamic-update="true" name="Resource.ResourceHourlyEmployee, Business" discriminator-value="3">
<property name="HourlySalary" column="resource_hourly_salary" type="System.Decimal" not-null ="false" />
</subclass>
<subclass dynamic-update="true" name="Resource.ResourceMonthlyEmployee, Business" discriminator-value="2">
</subclass>
<subclass dynamic-update="true" name="Resource.ResourceSubContractor, Business" discriminator-value="1">
</subclass>
</class>
When I try to "SaveOrUpdate" an existing resource all the values get updated as expected except the discriminator value itself (resource_type). Even though the object going in for update is of the correct/new type.
So how do I update that type/discriminator value of the object?
Couldnt find anything about this problem, hope someone can help or direct me to some help.
Regards,
Tobias Heed