Hi
I have encountered a strange problem with NHibernate. I have a class named Question, that has two subclasses. All three classes can be instantiated. I model them with joined-subclass elements as shown below:
Code:
<class name="CVAS.Primitives.Question, Test" table="Questions">
<id name="ID">
<generator class="native" />
</id>
<property name="Prompt" not-null="true" />
</class>
<joined-subclass name="CVAS.Primitives.CategoricalQuestion, Test" extends="CVAS.Primitives.Question, Test" table="CategoricalQuestions">
<key column="QuestionID" />
<list name="OptionsList" table="CategoricalOptions">
<key column="QuestionID" />
<index column="onum" />
<element column="Value" type="string" not-null="true" />
</list>
</joined-subclass>
<joined-subclass name="CVAS.Primitives.CompoundQuestion, Test" extends="CVAS.Primitives.Question, Test" table="CompoundQuestions">
<key column="QuestionID" />
<list name="QuestionList" table="ContainedQuestions" cascade="all-delete-orphan">
<key column="ID" />
<index column="qnum" />
<one-to-many class="CVAS.Primitives.Question, Test" />
</list>
</joined-subclass>
When I build my solution, I get the following items (among others) in the log:
Code:
2005-11-18 22:17:45,391 [4796] DEBUG NHibernate.Cfg.Binder [(null)] <(null)> - Second pass for collection: CVAS.Primitives.CategoricalQuestion.OptionsList
2005-11-18 22:17:45,391 [4796] DEBUG NHibernate.Cfg.Binder [(null)] <(null)> - Mapped collection key: QuestionID, index: onum, element: Value, type: String
2005-11-18 22:17:45,391 [4796] DEBUG NHibernate.Cfg.Binder [(null)] <(null)> - Second pass for collection: CVAS.Primitives.CompoundQuestion.QuestionList
2005-11-18 22:17:45,391 [4796] INFO NHibernate.Cfg.Binder [(null)] <(null)> - mapping collection: CVAS.Primitives.CompoundQuestion.QuestionList -> Questions
2005-11-18 22:17:45,391 [4796] DEBUG NHibernate.Cfg.Binder [(null)] <(null)> - Mapped collection key: ID, index: qnum, one-to-many: Question
I noticed that qnum, the index of the list, gets mapped to the table Question, rather than to CompoundQuestion as declared. This made me wonder how I model the relationship in which CompoundQuestion, a subclass of Question can hold a list of instances of Question. I wasn't able to find any examples that clearly demonstrated what I would like to do. While I could conceivably refactor my CompoundQuestion to be a non-Question, I was wondering if there was some way to model the structure as I have it now.
Thanks for any insight you have on this problem!
Gene