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.  [ 2 posts ] 
Author Message
 Post subject: Attributes and Composite-Id
PostPosted: Tue Feb 05, 2008 8:36 pm 
Newbie

Joined: Tue Feb 05, 2008 8:20 pm
Posts: 5
Hi I am traying to generate this map using Attributes (It already works as it is):

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"     namespace="Northwind.Domain.Entities" assembly="Northwind.Domain">
  <class name="Father" table="Fathers">
    <id name="FatherId" type="Int32" column="FatherId">
      <generator class="identity"/>
    </id>
    <property name="Name" column="name"/>
   
  </class>
  <class name="Mother" table="Mothers">
    <id name="MotherId" type="Int32" column="MotherId">
      <generator class="identity"/>
    </id>
    <property name="Name" column="name"/>
  </class>

  <class name="Son" table="Sons">   
    <composite-id name="Id" class="SonPK">
      <key-many-to-one name="Father" class="Father" column="FatherId"/>     
      <key-many-to-one name="Mother" class="Mother" column="MotherId"/>
      <key-property name="IdSon" column="SonId"/>
    </composite-id>
    <property name="Name" column="Name"/>
   
  </class>
  </hibernate-mapping>

This is where I got so far, but it is wrong:

Code:
namespace IIDEA.EALIB.AplicacionPrueba.PruebaAtrubutes
{
    [Class(Table = "Fathers")]
    public class Father
    {               
        private int fatherId;
        [Id(0, Name = "FatherId", Column = "FatherId", TypeType = typeof(Int32))]
        [Generator(1, Class = "identity")]       
        public virtual int FatherId
        {
            get { return fatherId; }
            set { fatherId = value; }
        }

        private string name;
        [Property(Name = "Name", Column = "name", TypeType = typeof(string), Length = 50)]
        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

    [Class(Table = "Mothers")]
    public class Mother
    {
        private int motherId;       
        [Id(0, Name = "MotherId", Column = "MotherId", TypeType = typeof(Int32))]
        [Generator(1, Class = "identity")]             
        public virtual int MotherId
        {
            get { return motherId; }
            set { motherId = value; }
        }

        private string name;
        [Property(Name = "Name", Column = "name", TypeType = typeof(string), Length = 50)]
        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }
    }


    [Serializable]
    [Class(Name = "SonPK")]
    public class SonPK
    {
        public SonPK()
        { }

        private int idSon;
        [KeyProperty(Column= "SonId")]
        public virtual int IdSon
        {
            get { return idSon; }
            set { idSon = value; }
        }

        private Mother mother;
        [KeyManyToOne(Class="Mother",Column="MotherId")]
        public virtual Mother Mother
        {
            get { return mother; }
            set { mother = value; }
        }

        private Father father;
        [KeyManyToOne(Class = "Father", Column = "FatherId")]
        public virtual Father Father
        {
            get { return father; }
            set { father = value; }
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            SonPK SonPKObj = obj as SonPK;
            if (SonPKObj == null)
                return false;

            if ((this.idSon == SonPKObj.IdSon) && (this.mother.MotherId == SonPKObj.mother.MotherId) && (this.father.FatherId == SonPKObj.father.FatherId))
            {
                return true;
            }

            return false;
        }
    }

    [Class(Table = "Sons")]
    public class Son
    {
        public Son()
        {
            id = new SonPK();
        }

        private SonPK id;
        [CompositeId(Class= "SonPK")]
        public virtual SonPK Id
        {
            get { return this.id; }
            set { this.id = value; }
        }

        private string name;
        [Property(Column= "name")]
        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }
    }
}


I found some references to some sites, but the sites are down. And I couldn't find any more information on the subject.
(I have many legacy systems)
Does any one faced this issue?
Thanks in advanced!


Top
 Profile  
 
 Post subject: Any one?
PostPosted: Fri Feb 08, 2008 7:10 pm 
Newbie

Joined: Tue Feb 05, 2008 8:20 pm
Posts: 5
Does any one faced this issue before? Any suggestion is welcome
Thanks :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.