views:

31

answers:

0

I have three classes:

  • Login
  • Role
  • LoginsInRoles

Login is one-many to LoginsInRoles and Role is one-many to LoginsInRoles. This is not a traditional many-many relationship because LoginsInRoles has to be a first class entity because it has additional properties that are unique to it.

I have set the cascade to delete for login and role relationships. Yet, when I try to delete a Login, Sql Server will disallow it because of the related child entities that are not deleted. It seems that NHibernate will not delete the child entities even with cascade delete setup. This architecture has worked fine for me when setting up simple one-to-many relationships but I suspect there is something about my mapping that is preventing it with the more complex relationship.

The related mappings:

Login Entity:

 <bag cascade="delete-orphan" name="LoginsInRoles" mutable="true">
      <key>
        <column name="Login_id" not-null="true" />
      </key>
      <one-to-many class="LeafAndBeanSoftware.Domain.Infrastructure.LoginsInRoles, LeafAndBeanSoftware.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </bag>

Role Entity

<bag cascade="delete" name="LoginsInRoles" mutable="true">
      <key>
        <column name="Role_id" />
      </key>
      <one-to-many class="LeafAndBeanSoftware.Domain.Infrastructure.LoginsInRoles, LeafAndBeanSoftware.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </bag>

LoginsToRoles Entity

<many-to-one class="LeafAndBeanSoftware.Domain.Infrastructure.Login, LeafAndBeanSoftware.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Login" update="false">
      <column name="Login_id" />
    </many-to-one>
    <many-to-one class="LeafAndBeanSoftware.Domain.Infrastructure.Role, LeafAndBeanSoftware.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Role" update="false">
      <column name="Role_id" />
    </many-to-one>
    <many-to-one class="LeafAndBeanSoftware.Domain.Infrastructure.Account, LeafAndBeanSoftware.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Account" update="false">
      <column name="Account_id" />
    </many-to-one>

Any suggestions about what I am doing wrong?