If you modify the 'StoreProduct' table, so that it has no surrogate primary key, but a primary key which exists of the 2 foreign key columns (ProductId & StoreId), then you can simply limit yourself to 3 entities: - Employee - Product - Store
Your Store class could then have a Set of Products, which can simply be mapped as a many-to-many relationship.
public class Store
{
public int Id {get;set;}
public string Name {get;set;}
public ISet<Product> Products = new HashedSet<Product>();
}
And in the Store.hbm.xml mapping:
<set name="Products" table="StoreProducts">
<key column="Store_Id" />
<many-to-many class="Product" column="Product_Id" />
</set>
So, to answer your question: first option is better.
Frederik Gheysels
2009-04-01 12:21:13