Barbaros Alp
Barbaros Alp

Reputation: 6434

Deleting item from many to many reference table?

I have two tables "Group" and "Customer" and of course two entities "Group" and "Customer". And i have another table which is referencing both "CustomerGroupMember" table.

I use CustomerGroupMember table for many-to-many mapping.

Customer.hbm.xml

<!--Many to many-->
    <bag name="CustomerGroups" table="CustomerGroupMember" cascade="all" lazy="true">
      <key column="CustomerId" />
      <many-to-many class="CustomerGroup" column="CustomerGroupId" />
    </bag> 

Group.hbm.xml

<bag name="Members" table="CustomerGroupMember" cascade="all" lazy="true">
      <key column="CustomerGroupId" />
      <many-to-many class="Customer" column="CustomerId" />
</bag>

I haven't created an entity and mapping for "CustomerGroupMember" table.

My question is how can i delete a CustomerGroupMember from CustomerGroupMember table ? Do i need to create an entity for CustomerGroupMember in order to delete CustomerGroupMember or there is another way ?

Thank you very much.

Upvotes: 0

Views: 359

Answers (1)

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421978

To delete a relationship item between those tables, you should somehow be able to reference the exact row in the junction table which is not possible in your current mapping. Yes, you have to create an entity and mapping for the CustomerGroupMember table. Without a mapping, how can you tell which row you want to delete?

Upvotes: 1

Related Questions