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 with one-to-many -mapping
PostPosted: Wed Nov 26, 2008 6:45 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
Hi Forum...

I try to connect to Tables with "one-to-many".

First of all, here my hbm.xml's:

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  namespace="Database.Tables"
   assembly="Database" >
   <class
      name="FgBlocks"
      table="FgBlocks">
      <id
         name="Id">
         <generator
            class="guid" />
      </id>
      <property
         name="BlockName"
         length="255"
         not-null="true"
         unique="true" />
      <property
         name="FileName"
         length="255" />
      <property
         name="BlockType"
         not-null="true" />
      <bag
         name="FgBlockProperties"
         table="FgBlockProperties"
         cascade="all"
         inverse="true">
         <key
            column="BlockId"
            foreign-key="FK_Block" />
         <one-to-many
            class="Database.Tables.FgBlocksProperties, Database" />
      </bag>
   </class>
</hibernate-mapping>


the corresponding Class:
Code:
namespace Database.Tables
{
   
    public class FgBlocks
    {
        private Guid _id;
        private IList<FgBlocksProperties> _properties = new List<FgBlocksProperties>();
        private string _blockName;
        private string _fileName;
        private int _blockType;

        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual IList<FgBlocksProperties> Properties
        {
            get { return _properties; }
            set { _properties = value; }
        }

        public virtual string BlockName
        {
            get { return _blockName; }
            set { _blockName = value; }
        }

        public virtual string FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }

        public virtual int BlockType
        {
            get { return _blockType; }
            set { _blockType = value; }
        }

        ///<summary>Standard Konstruktor</summary>
        public FgBlocks()
        {
        }

        /// <summary>
        /// Konstruktor mit Blockname
        /// </summary>
        /// <param name="FgBlockName"></param>
        public FgBlocks(string FgBlockName)
        {
            this.BlockName = FgBlockName;
        }
    }
}


The sub-table hbm:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  namespace="Database.Tables"
   assembly="Database">
   <class
      name="FgBlocksProperties"
      table="FgBlocksProperties">
      <id
         name="Id">
         <generator
            class="guid" />
      </id>
      <property
         name="Block" />
      <property
         name="PropertyId"
         not-null="true" />
      <property
         name="Attribute" />
      <property
         name="BlockId" />
      <many-to-one
         name="BlockID"
         class="FgBlocks"
         column="BlockId"
         not-null="true"
         foreign-key="FK_Block" />
   </class>
</hibernate-mapping>


and it's Class:

Code:
namespace Database.Tables
{
    public class FgBlocksProperties
    {
        private Guid _id;
        private FgBlocks _block;
        private long _propertyId;
        private string _attribute;
        private Guid _blockId;

       
        public virtual Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual Guid BlockId
        {
            get { return _blockId; }
            set { _blockId = value; }
        }
       
        public virtual FgBlocks Block
        {
            get { return _block; }
            set { _block = value; }
        }

        public virtual long PropertyId
        {
            get { return _propertyId; }
            set { _propertyId = value; }
        }

         public virtual string Attribute
        {
            get { return _attribute; }
            set { _attribute = value; }
        }
    }
}


I hve massive problems to understand how the relation between the two tables have to be defined.

Could someone please comment / explain this to me?

Many thanks
Telefisch


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.