我在消息线程中有一个消息类。每条消息都有对线程根消息的引用:
<class name="Message">
...
<many-to-one name="Root" not-null="true"/>
</class>
<joined-subclass name="Comment" extends="Message">
...
</joined-subclass>
现在我想删除评论。这适用于除根注释之外的所有注释。删除根注释,其中 Root 属性指向消息本身,会产生以下异常:
NHibernate.PropertyValueException : not-null property references a null or transient value
at NHibernate.Engine.Nullability.CheckNullability(Object[] values, IEntityPersister persister, Boolean isUpdate)
at NHibernate.Event.Default.DefaultDeleteEventListener.DeleteEntity(IEventSource session, Object entity, EntityEntry entityEntry, Boolean isCascadeDeleteEnabled, IEntityPersister persister, ISet transientEntities)
at NHibernate.Event.Default.DefaultDeleteEventListener.OnDelete(DeleteEvent event, ISet transientEntities)
at NHibernate.Impl.SessionImpl.FireDelete(DeleteEvent event)
at NHibernate.Impl.SessionImpl.Delete(Object obj)
当我从 NHibernate 3.0 升级到 3.3 时,首先出现此错误。当我删除not-null
约束时,我得到一个 SQL 异常,指示违反了相应的列约束。现在我想知道为什么 NHibernate 实际上会尝试保存要删除的实体。有谁知道如何处理这个问题?