It's been a while since I looked into composite keys, but I believe you should be using HasMany in this case, not HasAndBelongsToMany.
I believe in the MenuUser class, you need BelongsTo for both Users and Menus. It may be helpful if you included your Menus class. Please let us know if you get it working. -Michael Maddox http://www.AgilityForORMs.com/Home/Products/AfoCastleActiveRecordModelCodeGenerator/ On Tue, Nov 30, 2010 at 7:12 AM, Adriano Ribeiro <[email protected]> wrote: > Hi, > > I would like ask your help, i have follow cenary: > > database tables > > Users > id <- table key > name > > Menus > id <- table key > text > > MenuUser > user_id <- composite > menu_id table key with user_id and menu_id > strTipAcess > > ActiveRecord map > > [ActiveRecord("Users", DynamicUpdate = true, Lazy = true)] > public class User > { > [PrimaryKey(PrimaryKeyType.Native)] > public virtual Int32 Id { get; set; } > > [Property] > public virtual String Name { get; set; } > > [HasAndBelongsToMany(typeof(MenuUser), > Table = "MenuUser", CompositeKeyColumnRefs = new String[] > { "user_id", "menu_id" }, > ColumnKey = "user_id", Lazy = true, Inverse = true, > Cascade = ManyRelationCascadeEnum.SaveUpdate)] > public virtual IList<MenuUser> Access { get; set; } > } > > > [ActiveRecord("MenuUser", DynamicUpdate = true, Lazy = true)] > public class MenuUser > { > [CompositeKey] > public virtual MenuUserKey Key { get; set; } > > [Property] > public virtual Char strTipAcess { get; set; } > } > > [Serializable] > public class MenuUserKey > { > [KeyProperty] > public virtual Int32 user_id{ get; set; } > > [KeyProperty] > public virtual Int32 menu_id{ get; set; } > } > > Error i get when i try use User.Access: > > NHibernate.MappingException: Repeated column in mapping for > collection: User.Access column: user_id > > I saw some exemples com ActiveRecord tests, and Monorails > documentations, but, any of this case are like this, because the > relationship table didn´t have attributes. > > > Any help is very appreciated, thanks guys. > > -- > You received this message because you are subscribed to the Google Groups > "Castle Project Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/castle-project-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
