Hi,
I'm using nhibernate 1.0.4 and I get an error when I try to map a collection to a class, which is a subclass of another class.
I get this error: Invalid column name 'userid'.
The mapping looks like this (only the essential properties are shown):
It's the users answers that gives me problems:
<class name="Business.Data.User, Business" table="`User`">
<cache usage="nonstrict-read-write"/>
<id name="Id" type="Int32" unsaved-value="0">
<column name="Id" sql-type="int" not-null="true" unique="true" index="PK_tblUser"/>
<generator class="native" />
</id>
<bag name="Answers" inverse="true" cascade="all" lazy="true">
<key column="userid" />
<one-to-many class="Business.Data.Answer, Business"></one-to-many>
</bag>
</class>
<class name="Business.Data.Post, Business" table="Post">
<cache usage="nonstrict-read-write"/>
<id name="Id" type="Int32" unsaved-value="0">
<column name="Id" sql-type="int" not-null="true" unique="true" index="PK_tblPost"/>
<generator class="native" />
</id>
<many-to-one name="User" class="Business.Data.User, Business">
<column name="UserId" />
</many-to-one>
<joined-subclass name="Business.Data.Answer, Business" table="AnswerPost">
<key column="PostId" />
<property name="PointsReceived" type="Int32" column="PointsReceived" />
<many-to-one name="Question" class="Business.Data.Question, Business">
<column name="QuestionId" />
</many-to-one>
<bag name="Ratings" inverse="true" cascade='all' lazy="true">
<key column="AnswerId" />
<one-to-many class="Business.Data.AnswerRating, Business"></one-to-many>
</bag>
</joined-subclass>
</class>
Since the Post and Answer classes are mapped to two different tables in the database, the query constructed tries to get the userid from the answer-table instead of the mother-post-table.
If I comment that collection out, the rest works without problems.
It seems to be an error in the framework to me, but maybe I'm doing something wrong?
Hope you can help, thanks.
David
|