为什么NHibernate设置了保存对象的属性值,使用的术语是替代?

时间:2009-11-19 12:28:56

标签: .net nhibernate

我使用NHibernate作为我的DAL。我的对象是版本化的。我注意到当我保存一个对象时,NHibernate再次设置映射的属性。这一切都始于AbstractSaveEventListener.PerformSaveOrReplicate方法,该方法决定“替换”这些值。

无论如何,这是堆栈跟踪:

NHibernate.dll!NHibernate.LoadPropertyAccessor.LoadPropSetter.Set(object target = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, object value = "N_943918828") Line 101 C#
NHibernate.dll!NHibernate.Bytecode.Lightweight.AccessOptimizer.OnSetterCallback(object target = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, int i = 1, object value = "N_943918828") Line 42 + 0x29 bytes C#
[Lightweight Function] 
NHibernate.dll!NHibernate.Bytecode.Lightweight.AccessOptimizer.SetPropertyValues(object target = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, object[] values = {object[6]}) Line 32 + 0x20 bytes C#
NHibernate.dll!NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(object entity = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, object[] values = {object[6]}) Line 292 + 0x1e bytes C#
NHibernate.dll!NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValues(object entity = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, object[] values = {object[6]}) Line 280 + 0xe bytes C#
NHibernate.dll!NHibernate.Persister.Entity.AbstractEntityPersister.SetPropertyValues(object obj = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, object[] values = {object[6]}, NHibernate.EntityMode entityMode = Poco) Line 3776 + 0x1d bytes C#
NHibernate.dll!NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(object entity = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, NHibernate.Engine.EntityKey key = {EntityKey[Dummy_xxSxTruexxx#b207b57a-d510-47a7-8a1a-b48fecddbd3c]}, NHibernate.Persister.Entity.IEntityPersister persister = {SingleTableEntityPersister(Dummy_xxSxTruexxx)}, bool useIdentityColumn = false, object anything = null, NHibernate.Event.IEventSource source = {NHibernate.Impl.SessionImpl}, bool requiresImmediateIdAccess = true) Line 245 + 0x48 bytes C#
NHibernate.dll!NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(object entity = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, object id = "b207b57a-d510-47a7-8a1a-b48fecddbd3c", NHibernate.Persister.Entity.IEntityPersister persister = {SingleTableEntityPersister(Dummy_xxSxTruexxx)}, bool useIdentityColumn = false, object anything = null, NHibernate.Event.IEventSource source = {NHibernate.Impl.SessionImpl}, bool requiresImmediateIdAccess = true) Line 187 + 0x21 bytes C#
NHibernate.dll!NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(object entity = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}, string entityName = null, object anything = null, NHibernate.Event.IEventSource source = {NHibernate.Impl.SessionImpl}, bool requiresImmediateIdAccess = true) Line 129 + 0x1b bytes C#
NHibernate.dll!NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(NHibernate.Event.SaveOrUpdateEvent event = {NHibernate.Event.SaveOrUpdateEvent}) Line 162 + 0x48 bytes C#
NHibernate.dll!NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(NHibernate.Event.SaveOrUpdateEvent event = {NHibernate.Event.SaveOrUpdateEvent}) Line 29 + 0xb bytes C#
NHibernate.dll!NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(NHibernate.Event.SaveOrUpdateEvent event = {NHibernate.Event.SaveOrUpdateEvent}) Line 148 + 0xe bytes C#
NHibernate.dll!NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(NHibernate.Event.SaveOrUpdateEvent event = {NHibernate.Event.SaveOrUpdateEvent}) Line 21 + 0xe bytes C#
NHibernate.dll!NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(NHibernate.Event.SaveOrUpdateEvent event = {NHibernate.Event.SaveOrUpdateEvent}) Line 53 + 0x14 bytes C#
NHibernate.dll!NHibernate.Impl.SessionImpl.FireSave(NHibernate.Event.SaveOrUpdateEvent event = {NHibernate.Event.SaveOrUpdateEvent}) Line 2629 + 0x1d bytes C#
NHibernate.dll!NHibernate.Impl.SessionImpl.Save(object obj = {Shunra.Infra.DummyEntity.DummyEntity`1[Tag_xxSxTruexxx] #b207b57a-d510-47a7-8a1a-b48fecddbd3c (N_943918828)}) Line 470 + 0x28 bytes C#

LoadPropertyAccessor是我们的自定义属性设置器(我们在我们的基础架构下使用CSLA业务对象,因此我们需要NHibernate在设置属性时调用LoadProperty方法,因此使用我们的自定义属性设置器。)

无论如何,所有属性都具有正确的值,但仍然会再次设置它们。我想知道为什么?

实体的映射是:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
  <class name="Shunra.Infra.DummyEntity.DummyEntity`1[[Tag_xxSxTruexxx, Shunra.Tags, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]],Shunra.Infra.DummyEntity"
         lazy="false" table="Dummy" entity-name="Dummy_xxSxTruexxx">
    <id name="Id" column="IdConstant" type="string">
      <generator class="assigned" />
    </id>
    <version name="m_lastChanged" column="LastChanged" access="field" generated="never" type="int" />
    <property name="Name" access="cslaloadprop" column="Name" type="string" />
    <property name="LinkReference" access="cslaloadprop" column="LinkReference" type="string" />
    <property name="LinkValue" access="cslaloadprop" column="LinkValue" type="string" />
    <property name="TypeName" column="Type" access="property" type="string" />
    <component name="ParentId" class="Shunra.Infra.Contract.EntityId,Shunra.Infra.Contract">
      <property name="IdAsDBValue" access="property" type="string" column="ParentId" />
      <property name="TypeAsDBValue" access="property" type="string" column="ParentType" />
    </component>
  </class>
</hibernate-mapping>

0 个答案:

没有答案