views:

559

answers:

0

I've seen a few examples of how to write an hbm mapping file that has composite keys and implements a one-to-many relationship but I haven't seen a good example of how to do it with NHibernate.Mapping.Attributes.

So, upon trying this 100 different ways I'm receiving an error: {"The element 'bag' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'key' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'element, one-to-many, many-to-many, composite-element, many-to-any' in namespace 'urn:nhibernate-mapping-2.2'."}

So, I've tried moving the one-to-many tag before the key and that doesn't work, I've tried renumbering the first parameters and that doesn't work. Any suggestions would be greatly appreciated. Also, in regard to the key property, how do I let it know which field to map it back to the parent?

My parent class is HeaderDAO and the child class is ProddataDAO. All of the ProddataDAO fields begin with 'P' and the HeaderDAO fields begin with 'H'.

[NHibernate.Mapping.Attributes.Bag(0, Name = "ProddataRecs", Table = "ProddataDAO",     Generic = true, Inverse = false, Lazy = NHibernate.Mapping.Attributes.CollectionLazy.True, Cascade = "none")]
    [NHibernate.Mapping.Attributes.Key(1, Column = "PCONO")]        
    [NHibernate.Mapping.Attributes.Key(1, Column = "PDVNO")]
    [NHibernate.Mapping.Attributes.Key(1, Column = "PCUST")]
    [NHibernate.Mapping.Attributes.Key(1, Column = "PJBNO")]
    [NHibernate.Mapping.Attributes.Key(1, Column = "PSJNO")]
    [NHibernate.Mapping.Attributes.Key(1, Column = "PDTTK")]
    [NHibernate.Mapping.Attributes.Key(1, Column = "PTKNO")]
    [NHibernate.Mapping.Attributes.Key(1, Column = "PWKAR")]
    [NHibernate.Mapping.Attributes.Key(1, Column = "PTSID")]       
    [NHibernate.Mapping.Attributes.OneToMany(2, Class = "HeaderDAO", NotFound=NHibernate.Mapping.Attributes.NotFoundMode.Ignore)]
    public virtual IList<ProddataDAO> ProddataRecs
    {
        get
        {
           return _prodList;
         }
         set
         {
           _prodList = value;
         }
     }