Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>NH sometimes requires to set references to null. Usually this is to avoid problems in models where circular references exist. But it is not always clever enough to find a way to avoid it, even if the is one.</p> <p>So it may require to allow nulls in some foreign key fields, of course not only in the mapping file, also in the database. It actually <em>should</em> solve the problem.</p> <hr> <p><strong>Alternatively</strong>, you could also delete the data table by table using HQL. This works fine in all cases where you don't have inheritance and if you know all entities and the order to delete them:</p> <pre><code>object entityId; // gets keys to delete List&lt;object&gt; keyIds = Session .CreateQuery("select id from Key where Entity = :entity") .SetEntity("entity", Entity) .List&lt;object&gt;(); // delete KeyAttribute which reference the key Session.CreateQuery("delete KeyAttribute where Key.id in (:keyIds)") .SetParameterList("keyIds", keyIds) .ExecuteUpdate(); // delete the keys Session.CreateQuery("delete Key where id in (:keyIds)") .SetParameterList("keyIds", keyIds) .ExecuteUpdate(); // get attributes to delete List&lt;object&gt; attributeIds = Session .CreateQuery("select id from Attribute where Entity = :entity") .SetEntity("entity", Entity) .List&lt;object&gt;(); // delete KeyAttributes which reference the attributes Session.CreateQuery("delete KeyAttribute where Attribute.id in (:attributeIds)") .SetParameterList("attributeIds", attributeIds ) .ExecuteUpdate(); // delete the attributes Session.CreateQuery("delete Attribute where id in (:attributeIds)") .SetParameterList("attributeIds", attributeIds ) .ExecuteUpdate(); Session.CreateQuery("delete Entity where id = :entityId") .SetParameter("entityId", Entity.Id) .ExecuteUpdate(); </code></pre> <p>Note:</p> <ul> <li>You may break the parameter lists into piece if they exceed the size of around 2000 (in SQL Server).</li> <li>The session gets out of synch when deleting directly in the database. This doesn't cause any problems when deleting is all you do. When you are doing other staff in the same session, clear the session after deleting.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload