NHibernate - 无法重新关联未初始化的瞬态集合

时间:2017-07-19 13:20:05

标签: c# nhibernate .net-4.5

CurrentSession对象中删除对象时,我得到以下堆栈跟踪:

at NHibernate.Event.Default.ProxyVisitor.ReattachCollection(IPersistentCollection collection, CollectionType type)
at NHibernate.Event.Default.WrapVisitor.ProcessCollection(Object collection, CollectionType collectionType)
at NHibernate.Event.Default.WrapVisitor.ProcessValue(Int32 i, Object[] values, IType[] types)
at NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object[] values, IType[] types)
at NHibernate.Event.Default.DefaultFlushEntityEventListener.WrapCollections(IEventSource session, IEntityPersister persister, IType[] types, Object[] values)
at NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event)
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event)
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at PXL.Product.Macrodissection.DAL.HibernateTissueMarkBatchDAO.Delete(TissueMarkBatch batchObject) in C:\Code\Philips.Pxl.Tissuemark\src\DAO.NHibernate\Dao\NHibernate\HibernateTissueMarkBatchDAO.cs:line 126
at _dynamic_PXL.Product.Macrodissection.DAL.HibernateTissueMarkBatchDAO.Delete(Object , Object[] )
at Spring.Reflection.Dynamic.SafeMethod.Invoke(Object target, Object[] arguments)
at Spring.Aop.Framework.DynamicMethodInvocation.InvokeJoinpoint()
at Spring.Dao.Support.PersistenceExceptionTranslationInterceptor.Invoke(IMethodInvocation invocation)

当我尝试删除复杂对象然后执行Flush时,会出现错误。该对象跨越许多类非常复杂,因此我无法发布完整的源代码。

用法

CurrentSession.Delete(instance);
CurrentSession.Flush();
CurrentSession.Evict(instance);

映射

<joined-subclass name="Batch, Dao" table="Batch" lazy="false">
  <key column="id"/>

  <property name="Archived" type="Boolean">
    <column name="archived" sql-type="bit" default="0" not-null="false"/>
  </property>

  <property name="TimeComplete" type="DateTime">
    <column name="timeComplete" sql-type="datetime" not-null="false"/>
  </property>

  <property name="IsManualBatch" type="Boolean" column="isManualBatch" not-null="true">
    <meta attribute="default-value">0</meta>
  </property>

  <bag name="BatchRun" inverse="true" lazy="true" cascade="delete">
    <key column="BatchID" on-delete="cascade"/>
    <one-to-many class="BatchRun, Dao"/>
  </bag>

  <bag name="Runs" cascade="none" lazy="true" table="BatchRun">
    <key column="BatchID" />
    <many-to-many column="RunID" class="Run,Dao" />
  </bag>

  <many-to-one name="CompletedBy" foreign-key="c6" cascade="none" column="completedBy"  class="User,Dao" />

  <property name="Status" type="Int32">
    <column name="status" sql-type="int" not-null="false"/>
  </property>

</joined-subclass>

似乎对象变得相关但我不确定为什么。我应该使用另一种CurrentSession方法吗?

我正在使用ASP.NET 4.5。我到处寻找,但似乎无法找到错误出现的原因并且堆栈跟踪告诉我很少。

0 个答案:

没有答案