0

ASP.NET site.
Constantly got the exception
LazyInitializationException: ... -Could not initialize proxy - no Session.

NHibernate.LazyInitializationException: Initializing[MyProj.MyClass#XXX]-Could not initialize proxy - no Session.   
   at NHibernate.Proxy.AbstractLazyInitializer.Initialize()
   at NHibernate.Proxy.DefaultLazyInitializer.Intercept(InvocationInfo info)
   at MyClassProxy.get_MyProjerty()
1
  • Would anybody advise me to delete this question as I've found with google stackoverflow.com/questions/7584315/… ? It is not exactly the same but I can try to post my answer there. Commented May 6, 2021 at 10:42

1 Answer 1

1
  • Caching
  • Plus lazy loading
  • Plus session closing for every request

We've cached NHibernate entities but this is a dangerous idea to cache ORM objects.

We could do the following

  • Convert an ORM entity object to a custom limited POCO (Plain Old CLR Object) and use it for caching.
  • The following is dangerous for huge entity objects with Many-To-Many or One-To-Many relations.
    • Disable lazy loading for a single request (if possible).
    • Use some deep cloning to create a deep copy.
  • Detach the ORM entity object from the context. But lazy loading properties can stay having the null.

Keep in mind that somebody my enable or disable lazy loading and you'll get in troubles for a long time. Or someone may manage the session lifetime in an unexpected way. Or the session could become corrupted if a DB connection became interrupted.

I don't know yet what guys will choose to fix this issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.