Skip to content

Entity with initialized lazy property loses the property value after deserialization #1481

Closed
@hazzik

Description

@hazzik

Probably a regression after b26e622 (NH-3058)

Extended test from NH-3058

[Test]
public void MethodShouldLoadLazyProperty()
{
	var serializationStream = new MemoryStream();
	using (var s = OpenSession())
	{
		using (var tx = s.BeginTransaction())
		{
			var book = s.Load<DomainClass>(1);

			Assert.False(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"));

			string value = book.LoadLazyProperty();

			Assert.That(value, Is.EqualTo("Some text"));
			Assert.That(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"), Is.True);


			tx.Commit();
		}

		new BinaryFormatter().Serialize(serializationStream, s);
		serializationStream.Flush();
	}
	serializationStream.Position = 0;
	var ss = (ISession) new BinaryFormatter().Deserialize(serializationStream);

	var book1 = ss.Get<DomainClass>(1);

	Assert.That(NHibernateUtil.IsPropertyInitialized(book1, "ALotOfText"), Is.True);
	Assert.That(book1.ALotOfText, Is.EqualTo("Some text")); //Null here
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions