Skip to content

Reconnect lazy property proxy on deserialization #1744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

fredericDelaporte
Copy link
Member

After deserializing a session holding entities with uninitialized lazy properties, the lazy properties cannot be accessed because their proxy does no more have a session.

This is an old issue, independent of the used proxy factory. (Provided it is considered that proxies should not serialize their session, in order to avoid serializing the whole session when just serializing one entity.)

// Reconnect the lazy property proxies
foreach (var p in entitiesByKey)
{
if (p.Value is IFieldInterceptorAccessor lazyPropertyProxy && lazyPropertyProxy.FieldInterceptor != null)
Copy link
Member Author

@fredericDelaporte fredericDelaporte Jun 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractEntityPersister.AfterReassociate does also this kind of things, but it is meant for detached entities and also handle dirtiness, which should be left untouched in the session deserialization case.

@fredericDelaporte fredericDelaporte force-pushed the LazyProxyDeserialization branch from 7323ddf to 3a795fe Compare June 11, 2018 16:54
Text = "Text1"
};
s.Save(se);
_idSimpleEntity1 = se.Id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to write _idSimpleEntity1 = (Guid)s.Save(se);. You can declare the _idSimpleEntity1 field as object and drop casting as the concrete type of the key does not matter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me as quite a matter of taste. I rather have two lines of code rather than a hard-coded cast. Granted, the test case does not need the exact typing of the id.

To be squashed.
@fredericDelaporte fredericDelaporte merged commit 067fc09 into nhibernate:master Jun 14, 2018
@fredericDelaporte fredericDelaporte deleted the LazyProxyDeserialization branch June 14, 2018 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants