I have a question about doing a mapping with a many-to-many table. My 3 tables look like this:
Product
======
product_id
product_name
ProductGroup
=======
product_group_id
product_group_name
ProductProductGroup
=======
product_id
product_group_id
order_index
The ProductProductGroup table provides a many-to-many relationship between the Product and ProductGroup tables. This is an existing database so I can't change the schema.
Currently I have the mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MyProducts.Product,MyProducts" table="Product">
<id name="ProductId" column="product_id" type="String">
<generator class="assigned"/>
</id>
<property name="ProductName" column="product_name" type="String" />
<set name="ProductGroupList" inverse="true" lazy="true" table="ProductProductGroup" >
<key column="product_id" />
<many-to-many class="MyProducts.ProductGroup,MyProducts" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MyProducts.ProductGroup,MyProducts" table="ProductGroup">
<id name="ProductGroupId" column="product_group_id" type="String">
<generator class="assigned"/>
</id>
<property name="ProductGroupName" column="product_group_name" type="String" />
<set name="ProductList" inverse="true" lazy="true" table="ProductProductGroup" >
<key column="product_group_id" />
<many-to-many class="MyProducts.Product,MyProducts" />
</set>
</class>
</hibernate-mapping>
How do I include order_index from the many-to-many table in both mappings? Or do I need to create a third class for the many-to-many table?