Skip to content

ISession.Refresh does not update lazy properties #3622

@ValResnick

Description

@ValResnick

Hi,

we have noticed a problem in versions 4.4.9 and 5.5.2. In version 5.2.1 we did not have this problem, I suspect it is related to the lazy property changes in version 5.3 (116398d).

The following scenario:
We have opened a session with objects and also open another session and edit an object there, which is already loaded in the first session. We call Refresh so that this object is up-to-date in the previous session. Unfortunately, in the versions above, the lazy properties are no longer updated, but contain the previous and therefore old value.

Reproduction:

[Test] // In Class FetchLazyPropertiesFixture
public void Bug()
{
	using (var outerSession = OpenSession())
	{
		const string query = "from Person fetch Image where Id = 1";
		const string namePostFix = "_MODIFIED";
		const int imageLength = 4711;
		
		Person outerPerson = outerSession.CreateQuery(query).UniqueResult<Person>();
		
		Assert.That(outerPerson.Name.EndsWith(namePostFix), Is.False); // Normal property 
		Assert.That(outerPerson.Image.Length, Is.EqualTo(1)); // Lazy Property
		
		// Changing the properties of the person in a different sessions
		using (var innerSession = OpenSession())
		{
			var transaction = innerSession.BeginTransaction();
		
			Person innerPerson = innerSession.CreateQuery(query).UniqueResult<Person>();
			innerPerson.Image = new byte[imageLength];
			innerPerson.Name += namePostFix;
			innerSession.Update(innerPerson);
			
			transaction.Commit();
		}
		
		// Refreshing the person in the outer session
		outerSession.Refresh(outerPerson);
		
		Assert.That(outerPerson.Name.EndsWith(namePostFix), Is.True); // Value has changed
		Assert.That(outerPerson.Image.Length, Is.EqualTo(imageLength)); // This is still the old value
	}                                                                                                 
}

Best regards,
Thomas

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions