views:

13

answers:

0

Hello, I have some annoying problem with NHibernate and deletion of classes. I have a rather complicated tree-like class diagram, where the "leaves" are abstract classes with many different "sons". I have no problem with saving or updating it, but I have some annoying problems with delete, so I decided to change the cascades to "save-update" and to manually cascade myself for deletion.

But the problem persisted. I have this annoying exception:

could not delete collection rows: [VisualTrainer.Clases.Modulo.Temas#3][SQL: UPDATE Tema SET id_Modulo = null WHERE id_Modulo = ?p0 AND id_tema = ?p1]

What I understand from that is that NHibernate is trying to Update a possible reference in "temas" table, but obviously, "temas" table doesn't exist because "Tema" is an abstract class.

If I change the Mapping, stating that "Tema" is not abstract, it works perfectly. But I DON'T want this because NHibernate starts saving redundant information (in "Temas" table and the child's table). ¿Is there a way to make NHibernate not trying to update the non-existent table?. Any Help will be highly appreciated.

By the way this is the mapping of "Tema" and his heritage, in case you need it.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="VisualTrainer" namespace="VisualTrainer.Clases">
  <class name="Tema" abstract="true">
    <id name="Id" column="id_tema">
      <generator class="hilo"/>
    </id>
    <property name="Nombre" />
    <property name="Descripcion" />
    <many-to-one name="FatherModulo" class ="Modulo" column="id_modulo"/>
    <union-subclass table="Lectura" name="Lectura">
      <property name="Texto" length="32557"/>
    </union-subclass>
    <union-subclass name="Video" table="Video">
      <bag name="Helptexts" cascade="save-update">
        <key column="id_tema"/>
        <one-to-many class="HelpText"/>
      </bag>
      <property name="Ubicacion"/>
    </union-subclass>
    <union-subclass name="ImgShow" table="ImgShow">
      <property name="Imgs"/>
      <property name="Contenido"/>
    </union-subclass>
  </class>
</hibernate-mapping>