I am having big trouble with a many-to-many represented as a one-to-many. I have a "Group" object and a "Seller" object. A "Seller" can belong to many groups, and a "Group" can have many Sellers. the mapping of these two entities require specific properties defining the relationship between "seller" and "group".
So I have mapped the relations hip using a "SellerGroupMapping" object and a one-to-many. I only want to add a Seller to a Group not vice versa. So I have a method that adds mapping to the group. And I then want to save the group. (not save each mapping individually).
But nhibernate does not like this, I get SQL concurrency errors in that it cannot find the group in the database when it does in fact exist.
Here is my mapping file fro the SellerGroupMapping object:
Code:
<class name="SellerGroupMapping" table="Map_Sellers_Groups">
<composite-id>
<key-many-to-one name="Group" class="Group" column="GroupID" />
<key-many-to-one name="Seller" class="Seller" column="SellerID" />
</composite-id>
<property name="SKChaseOnlinePublicCommission" column="SKCOnlinePublicCommission" />
<property name="SKChaseOnlinePrivateCommission" column="SKCOnlinePrivateCommission" />
<property name="SKChaseOfflineCommission" column="SKCOfflineCommission" />
<property name="GroupOnlinePublicCommission" column="GroupOnlinePublicCommission" />
<property name="GroupOnlinePrivateCommission" column="GroupOnlinePrivateCommission" />
<property name="GroupOfflineCommission" column="GroupOfflineCommission" />
<property name="FulfilmentCost" column="Fulfilment" />
</class>
Mapping file for the group:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SKChase.Model" namespace="SKChase.Model">
<class name="Group" table="Groups">
<id name="Id" type="Int32" column="ID" unsaved-value="-1" access="nosetter.pascalcase-underscore">
<generator class="identity" />
</id>
<property name="Name" type="String" length="100" unique="true"/>
<property name="Active" type="Boolean" />
<property name="Type" type="SKChase.Model.GroupType, SKChase.Model" />
<bag name="SellerMappings"
table="Map_Sellers_Groups" cascade="save-update"
inverse="false" lazy="true" access="nosetter.pascalcase-underscore">
<key column="GroupID" />
<one-to-many class="SKChase.Model.SellerGroupMapping, SKChase.Model" not-found="ignore" />
</bag>
<many-to-one name="Properties" column="PropertySetID" class="PropertyData" cascade="all" fetch="join" />
</class>
Can you please point out any glaring errors?