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