views:

26

answers:

1

Hello hope someone can help me on this.

I have a situation where I have: User entity which stores all my users including admins. Comments entity which stores all comment against users.

my problem is I'm also storing within the comment entity the user id of the admin who made the comment. So now I have the Comment entity having 2 userId fields and when retrieving a User entity it wouldn't fetch any associating comments.

My mapping code is as below:

Within the User Entity..

<set name="MemberComments" cascade="all-delete-orphan" inverse="true">
  <key column="UserCommentId"/>
  <one-to-many class="IlluminatiCoreUserComment"/>
</set>

Within the UserComment Entity

<id name="UserCommentId">
  <generator class="identity"/>
</id>
<many-to-one name="User" class="IlluminatiCoreMember" column="UserId" not-null="true"/>
<property name="Comment" not-null="true"/>
<property name="CreatedTimeStamp" not-null="true"/>
<property name="ModifiedTimeStamp" not-null="true"/>
<many-to-one name="CommentedByUser" class="IlluminatiCoreMember" column="CommentedByUserId" not-null="true"  inverse="false"/>

How can I make MemberComments within the User entity point to just the User many-to-one field?

Thanks for your help in advance

A: 

The <key> element in User should have the FK to User, not the id of UserComment.

In other words, the same column as the many-to-one, UserId.

Diego Mijelshon