Please use the NHibernate mailing list http://groups.google.com/group/nhusers
Alternatively, you may choose our commercial support option: http://nhprof.com/commercialsupport On Sat, May 14, 2011 at 3:14 PM, sando <[email protected]> wrote: > I am stuck at a problem where we have multiple many-to-many > relationships to be mapped from a POCO to a single mapping table. > Unfortulately I can not change the POCO, neither the DataModel. > > To differentiate multiple M-M we have a field in our mapping table of > type int. > This filed has to be set while we insert into the mapping table. > > This would help us to use "where" to fetch them into appropriate > collection while retrieving. > > While writing the hbm for it I saw that while insert everything works > fine, but the TYPE column remains 'NULL' > > Consequently, while retrieve everything comes to all the collections > in the POCO; if we do not put the "where" clause. > If we put the "where" then both collections remain empty. > > Assume the class model as follows: > > class Stock > { > public int? Id {get; set;} > public string StockName {get; set;} > > public IList<Category> PublicCategories {get; set;} > public IList<Category> PrivateCategories {get; set;} > } > > class Category > { > public int? Id {get; set;} > public string CategoryName {get; set;} > } > > I have 2 tables: > StockTable > [id(int), Name(varchar)] > > CategoryTable > [id(int), Name(varchar)] > > Stock_Category_Table > [Stock_id(int), Category_id(int), TYPE(int)] > > This is my mapping, partially: > > <bag name="categories" table="Stock_Category" cascade="all" > lazy="false" where="TYPE=1"> > <key column="STOCK_ID" /> > <many-to-many class="Category" column="CATEGORY_ID" /> > </bag> > - <bag name="categories2" table="Stock_Category" cascade="all" > lazy="false" where="TYPE=2"> > <key column="STOCK_ID" /> > <many-to-many class="Category" column="CATEGORY_ID" /> > </bag> > > I tried putting multiple columns in the mapping table and check for > not null as proposed in: > https://forum.hibernate.org/viewtopic.php?f=25&t=953401 > > This works, but the solution is not elegant and does not support our > project design. > We need a way to set the mapping table column "TYPE" when we insert > every record. > > Regards, > sando > -- You received this message because you are subscribed to the Google Groups "nhusers" 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/nhusers?hl=en.
