NHibernate 3.2 Object isn't updated during flush when lazy property is used

淺唱寂寞╮ 提交于 2019-12-12 13:44:34

问题


I use lazyload property in my entity. It works correct, but NHibernate doesn't make update when any property in this class is changed via method. If property is changed directly then all is ok.

I suppose that problem in that in case of lazy property proxy object is returned and this proxy doesn't handle inner changes.

I have added test code below. It works fine in NHibernate 3.1 but update isn't called in NHibernate 3.2 and 3.3

Maybe someone know how to solve this problem?

Thanks.

Entity:

/// <summary>
/// Class for testing lazy properties.
/// </summary>
public class TestClass
{
    public virtual int Id { get; set; }
    public virtual string LazyData { get; set; }
    public virtual string TestData { get; set; }

    public virtual void ChangeTestData(string data)
    {
        TestData = data;
    }
}

Mapping:

public class TestClassMap : ClassMap<TestClass>
{
    public TestClassMap()
    {
        Id(m => m.Id);
        Map(m => m.LazyData).LazyLoad();
        Map(m => m.TestData);
    }
}

Test code:

[Test]
public void LazyProperityTest1()
{
    var testObj = new TestClass();
    Session.Save(testObj);
    Session.Flush();
    Session.Clear();

    // Change property and flush session.
    var persistedObj = Session.CreateCriteria<TestClass>().List<TestClass>().First();
    persistedObj.ChangeTestData("test");

    Session.Flush();
    Session.Clear();
}

Generated sql requests when LazyLoad is set:

NHibernate: INSERT INTO "TestClass" (LazyData, TestData) VALUES (@p0, @p1); select last_insert_rowid();@p0 = NULL [Type: String (0)], @p1 = NULL [Type: String (0)]
NHibernate: SELECT this_.Id as Id0_0_, this_.TestData as TestData0_0_ FROM "TestClass" this_

Generated sql requests when LazyLoad is not set:

NHibernate: INSERT INTO "TestClass" (LazyData, TestData) VALUES (@p0, @p1); select last_insert_rowid();@p0 = NULL [Type: String (0)], @p1 = NULL [Type: String (0)]
NHibernate: SELECT this_.Id as Id0_0_, this_.LazyData as LazyData0_0_, this_.TestData as TestData0_0_ FROM "TestClass" this_
NHibernate: UPDATE "TestClass" SET LazyData = @p0, TestData = @p1 WHERE Id = @p2;@p0 = NULL [Type: String (0)], @p1 = 'test' [Type: String (0)], @p2 = 1 [Type: Int32 (0)]

回答1:


This definitely looks like a bug to me, and you have a good test case to prove it.

Please enter an issue at https://nhibernate.jira.com/



来源:https://stackoverflow.com/questions/15392545/nhibernate-3-2-object-isnt-updated-during-flush-when-lazy-property-is-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!