-->
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.  [ 4 posts ] 
Author Message
 Post subject: ManyToOne attributes as inverse to List attribute
PostPosted: Sun Dec 18, 2005 5:37 pm 
Newbie

Joined: Wed Nov 16, 2005 2:40 pm
Posts: 19
Location: Palo Alto, CA
I have a class that holds a list of other classes, as follows:

Code:
// UniqueObject defines the ID attribute.
[NHibernate.Mapping.Attributes.Class(Table="AnalysisData")]
public class AnalysisData : UniqueObject
{
   #region Properties
   private IList analysisResultsList = new ArrayList();
   [NHibernate.Mapping.Attributes.List(Cascade=CascadeStyle.AllDeleteOrphan)]
   [NHibernate.Mapping.Attributes.Key(1, Column="AnalysisDataID")]
   [NHibernate.Mapping.Attributes.Index(2, Column="AnalysisDataSequence")]
   [NHibernate.Mapping.Attributes.OneToMany(3, ClassType=typeof(AnalysisResult))]
   public IList AnalysisResultsList
   {
      get { return this.analysisResultsList; }
      set { this.analysisResultsList = value; }
   }
}


and

Code:
[NHibernate.Mapping.Attributes.Class(Table="AnalysisResults")]
public class AnalysisResult: UniqueObject
{
   #region Properties
   private string description;
   /// <summary> Textual description</summary>
   [NHibernate.Mapping.Attributes.Property]
   public string Description
   {
      get { return this.description; }
      set { this.description = value; }
   }
   // other properties deleted for clarity...
   #endregion Properties
}


I understand that to get the list objects to be retrieved, I need a ManyToOne element in the AnalysisResult class, but I don't understand how I attach it if my DOM doesn't have a parent property.

Ideas?

Thanks!

Gene


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 7:50 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I am not sure to understand your problem... You need a relationship in the mapping whenever you want to be able to browse it that way.
So you need a ManyToOne if you want to be able to go from the Many side to the One side.

I move this topic as it has nothing to do with a Contribution/Tool.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 12:58 pm 
Newbie

Joined: Wed Nov 16, 2005 2:40 pm
Posts: 19
Location: Palo Alto, CA
KPixel wrote:
I am not sure to understand your problem... You need a relationship in the mapping whenever you want to be able to browse it that way.
So you need a ManyToOne if you want to be able to go from the Many side to the One side.

I move this topic as it has nothing to do with a Contribution/Tool.


I am sorry I was not clear. I am posting to this list because I believe the question is related to NHibernate.Mapping.Attributes. If this is the wrong place for that discussion, I apologize for my misunderstanding.

I don't want to have a child->parent link, but I want to have a NHibernate.Mapping.Attributes.List in the parent that contains a bunch of children. When I just code the list, however, the childrens' index fields are not saved when they are written into the database. My interpretation of the documentation was that I needed a ManyToOne attribute on the child to represent the index field (that is, a reference to the parent instance). My question is how I specify that attribute when my DOM doesn't call for a child->parent link. (And furthermore, Sergey pointed out that it's not possible to have bi-directional links with Lists.)

Thanks for your help,

Gene


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 5:58 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate assumes that the collection belongs to the parent and will set the child indices when the parent is saved.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.