-->
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: Problem - Mapping 1 column to multiple properties
PostPosted: Sat Jul 17, 2010 3:26 pm 
Newbie

Joined: Fri Aug 01, 2008 2:20 pm
Posts: 6
Hello all,

I have a "Message" table:
- MessageId (guid)
- Subject
- Body

and "Comment" table
- CommentId (guid)
- ContainerId (guid)
- Content

The "ContainerId" refers to MessageId or CommentId.
If "ContainerId" refers to MessageId then it means that Comment replies to a Message.
If "ContainerId" refers to CommentId then it means that Comment replies to a Comment.


Here is my message class:

Code:
    public class Message : ProjectEntity
    {

        public Message()
        {
        }



        ///<summary>
        ///  Gets or sets the MessageId of the Message.
        ///</summary>
        ///
        public Guid MessageId
        {
            get
            {
                return this.messageId;
            }
            set
            {
                this.messageId = value;
            }
        }
        private Guid messageId = Guid.Empty;


        ///<summary>
        ///  Gets or sets the Subject of the Message.
        ///</summary>
        ///
        public string Subject
        {
            get
            {
                return this.subject;
            }
            set
            {
                this.subject = value;
            }
        }
        private string subject = string.Empty;

        ///<summary>
        ///  Gets or sets the Body of the Message.
        ///</summary>
        ///
        public string Body
        {
            get
            {
                return this.body;
            }
            set
            {
                this.body = value;
            }
        }
        private string body = string.Empty;



Here is Comment class:

Code:
   public class Comment
    {

        public Comment()
        {
        }

        #region Public Properties
        ///<summary>
        ///  Gets or sets the CommentId of the Comment.
        ///</summary>
        ///
        public Guid CommentId
        {
            get
            {
                return this.commentId;
            }
            set
            {
                this.commentId = value;
            }
        }
        private Guid commentId = Guid.Empty;

        ///<summary>
        ///  Gets or sets the Message of the Comment.
        ///</summary>
        ///
        public Message Message
        {
            get
            {
                return this.message;
            }
            set
            {
                this.message = value;
            }
        }
        private Message message;

        ///<summary>
        ///  Gets or sets the Message of the Comment.
        ///</summary>
        ///
        public Comment Parent
        {
            get
            {
                return this.parent;
            }
            set
            {
                this.parent = value;
            }
        }
        private Comment parent;
....


and here is my mapping file:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Blog.Comment, Blog" table="Blog_Comments" lazy="false">
    <id name="CommentId" column="CommentId" type="Guid">
      <generator class="guid" />
    </id>
    <many-to-one cascade="none" name="Message" class="Blog.Message, Blog" column="ContainerId" foreign-key="MessageId" />
    <many-to-one cascade="none" name="Parent" class="Blog.Comment, Blog" column="ContainerId" foreign-key="CommentId" />
    <property name="Content" type="string"/>
  </class>
</hibernate-mapping>


However I always receive error "Column name 'ContainerId' appears more than once in the result column list" when trying to save a Comment.

My question is that if NHibernate supports mapping 1 column to multiple properties, in this case this is "ContainerId" column and 2 properties are Message and Parent.

Thanks,


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.