-->
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: Issue with a simple One-to-Many relationship. Help please
PostPosted: Sat Aug 20, 2011 8:49 pm 
Newbie

Joined: Sat Aug 20, 2011 8:39 pm
Posts: 1
Hi

I meet an issue that I cannot fix. Using a one-to-many relationship, I get the correct number of results but their value is always the one of the first element.

Here are my two tables:
Image

I try to get all the directoryId values associated to a FormID. In my example, 1 and 70041.


Here are my domain files:
Code:
public class FormsDirectory : DomainObject<int>
    {
        public FormsDirectory()
            : base()
        {
        }

        public virtual int FormId
        {
            get;
            set;
   }

(...)

        public override int GetHashCode()
        {
            return this.DirectoryId.GetHashCode();
        }
     }


and
Code:
public class Form : DomainObject<int>
    {

        private string name;


        private string formNameKey;

(...)

public virtual IList<FormsDirectory> FormsDirectory
        {
            get { return this.formsDirectory; }
            set { this.formsDirectory = value; }
        }

        public override int GetHashCode()
        {
            return this.Name.GetHashCode();
        }
    }


And Here are my mapping files:
Code:
<class name="Form" table="ModuleForms" lazy="true" where="FormFields is not null and FormId not in ( select e.FormId from tblEvents e) ">
      <id name="Id" type="System.Int32" column="FormId">
         <generator class="identity" />
      </id>
   

(...)

    <one-to-one name="SubmittedForm" class="SubmittedForm" foreign-key="FormId"/>

    <bag name="FormsDirectory" table="lnkFormsDirectory" inverse="true" lazy="true">
      <key column="FormID" />
      <one-to-many class="FormsDirectory"/>
    </bag>

</class>



AND

Code:
  <class name="FormsDirectory" table="lnkFormsDirectory" mutable="false">
   
    <id name="Id" type="System.Int32" column="FormID">
      <generator class="increment"/>
    </id>

(...)
   
  </class>


In IList<FormsDirectory> recipients = this.CurrentForm.Form.FormsDirectory, I get two results (for for each entry, that's okay), but the FormsDirectory[X].DirectoryId value is always equals to 1, the value of the first entry.

I really need your help folks,
Thank you


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.