-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping question
PostPosted: Wed Apr 12, 2006 10:08 am 
Newbie

Joined: Tue Apr 11, 2006 1:28 pm
Posts: 6
I have looked and looked, and been unable to find the solution for this problem.

Assume I have two tables: ProjectTypeA, ProjectTypeB

Both ProjectTypeA and ProjectTypeB have a list of tasks to be completed. The information required for the tasks is identical.

In the interest of reusing objects, I have a single object called a Task which is stored in a table called Task. The assumption is that I can use a discriminator column to identify which project type the task belong to.

Here is my mapping file to this point:

Code:
<class name="ProjectTypeA" table="ProjectTypeA">
   <id name="id" type="integer" unsaved-value="undefined">
      <generator class="native"/>
   </id>
   ...
   <bag name="Task"  where="TaskType='ProjectTypeA'" cascade="delete-orphan">
      <key column="parentID" />
      <one-to-many class="Task"/>
   </bag>
</class>

<class name="ProjectTypeB" table="ProjectTypeB">
   <id name="id" type="integer" unsaved-value="undefined">
      <generator class="native"/>
   </id>
   ...
   <bag name="Task"  where="TaskType='ProjectTypeB'" cascade="delete-orphan">
      <key column="parentID" />
      <one-to-many class="Task"/>
   </bag>
</class>


<class name="Task" table="Task">
   <id name="id" type="integer" unsaved-value="undefined">
      <generator class="native"/>
   </id>
   <discriminator column="parentLocation"/>
   ...
</class>


Using this creates the Task record and parentID is correct, but the descriminator field parentLocation is filled in with the Task class instead of the project type.

Is there a better approach, or am I missing the obvious?

I tried to use "any" but it seemed to complicate things more than it helped. And I was still unable to get the correct parentLocation.

thanks for the help.
Mike


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

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.