NHibernate使用组件抛出强制转换异常

时间:2012-10-13 14:08:49

标签: nhibernate mapping

我正在使用NHibernate,我与删除级联有一对多的关系。下面的映射。

<class name="Photo" table="photos">

  <id name="RoomId" column="room_id">
    <generator class="guid"/>
  </id>

  // omitted for brevity

  <component name="Data" class="PhotoData" lazy="true">
    <property name="Mime" column="mime"/>
    <property name="Data" column="data" length="2048000"/>
  </component>
</class>

<class name="Room" table="rooms">

  // omitted for brevity

  <bag name="Photos" lazy="false" fetch="join" cascade="delete" inverse="true">
    <key>
      <column name="room_id"/>
    </key>
    <one-to-many class="Photo"/>
  </bag>
</class>

当我尝试删除房间时,我收到以下异常

Unable to cast object of type 'System.Object' to type 'PhotoData'

如果我从照片映射中删除该组件,我可以毫无问题地删除房间和所有照片。

有什么建议吗?

更新:根据@nemesv的评论

堆栈跟踪在下面,没有内部异常。

at (Object , GetterCallback )
at NHibernate.Bytecode.Lightweight.AccessOptimizer.GetPropertyValues(Object target) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Bytecode\Lightweight\AccessOptimizer.cs:line 27
at NHibernate.Tuple.Component.PocoComponentTuplizer.GetPropertyValues(Object component) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Tuple\Component\PocoComponentTuplizer.cs:line 68
at NHibernate.Type.ComponentType.GetPropertyValues(Object component, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Type\ComponentType.cs:line 291
at NHibernate.Engine.ForeignKeys.Nullifier.NullifyTransientReferences(Object value, IType type) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs:line 74
at NHibernate.Engine.ForeignKeys.Nullifier.NullifyTransientReferences(Object[] values, IType[] types) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs:line 38
at NHibernate.Event.Default.DefaultDeleteEventListener.DeleteEntity(IEventSource session, Object entity, EntityEntry entityEntry, Boolean isCascadeDeleteEnabled, IEntityPersister persister, ISet transientEntities) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultDeleteEventListener.cs:line 204
at NHibernate.Event.Default.DefaultDeleteEventListener.OnDelete(DeleteEvent event, ISet transientEntities) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultDeleteEventListener.cs:line 111
at NHibernate.Impl.SessionImpl.FireDelete(DeleteEvent event, ISet transientEntities) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 2478
at NHibernate.Impl.SessionImpl.Delete(String entityName, Object child, Boolean isCascadeDeleteEnabled, ISet transientEntities) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 975
at NHibernate.Engine.CascadingAction.DeleteCascadingAction.Cascade(IEventSource session, Object child, String entityName, Object anything, Boolean isCascadeDeleteEnabled) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\CascadingAction.cs:line 158
at NHibernate.Engine.Cascade.CascadeToOne(Object parent, Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Cascade.cs:line 216
at NHibernate.Engine.Cascade.CascadeAssociation(Object parent, Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Cascade.cs:line 181
at NHibernate.Engine.Cascade.CascadeProperty(Object parent, Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Cascade.cs:line 148
at NHibernate.Engine.Cascade.CascadeCollectionElements(Object parent, Object child, CollectionType collectionType, CascadeStyle style, IType elemType, Object anything, Boolean isCascadeDeleteEnabled) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Cascade.cs:line 240
at NHibernate.Engine.Cascade.CascadeCollection(Object parent, Object child, CascadeStyle style, Object anything, CollectionType type) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Cascade.cs:line 201
at NHibernate.Engine.Cascade.CascadeAssociation(Object parent, Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Cascade.cs:line 185
at NHibernate.Engine.Cascade.CascadeProperty(Object parent, Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Cascade.cs:line 148
at NHibernate.Engine.Cascade.CascadeOn(IEntityPersister persister, Object parent, Object anything) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Cascade.cs:line 126
at NHibernate.Event.Default.DefaultDeleteEventListener.CascadeBeforeDelete(IEventSource session, IEntityPersister persister, Object entity, EntityEntry entityEntry, ISet transientEntities) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultDeleteEventListener.cs:line 253
at NHibernate.Event.Default.DefaultDeleteEventListener.DeleteEntity(IEventSource session, Object entity, EntityEntry entityEntry, Boolean isCascadeDeleteEnabled, IEntityPersister persister, ISet transientEntities) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultDeleteEventListener.cs:line 202
at NHibernate.Event.Default.DefaultDeleteEventListener.OnDelete(DeleteEvent event, ISet transientEntities) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultDeleteEventListener.cs:line 111
at NHibernate.Event.Default.DefaultDeleteEventListener.OnDelete(DeleteEvent event) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultDeleteEventListener.cs:line 30
at NHibernate.Impl.SessionImpl.FireDelete(DeleteEvent event) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 2465
at NHibernate.Impl.SessionImpl.Delete(Object obj) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 508
at DataAccess.Respository`1.<>c__DisplayClass7.<Delete>b__6(ISession s) in D:\svn\flatsharespa\DataAccess\Respository.cs:line 4

0 个答案:

没有答案