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)]