These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Updating a Discriminator value
PostPosted: Tue Jul 11, 2006 10:37 am 
Newbie

Joined: Tue Jul 11, 2006 10:00 am
Posts: 1
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 2:44 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This is not really possible in NHibernate since objects don't actually change their class at runtime in .NET. Either change the discriminator using direct SQL, or delete the old instance and insert a new one, or re-think your domain model.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.