In the context of the Windows web service, which is designed to run tasks, we are trying to reuse the NHibernate DAL that we developed for the web application.
For session management, we have two options, each of which has its own advantages and disadvantages:
Sessional session
- Continues to grow as it tracks everything (L1 cache / session)
- It is necessary to close the session carefully, it seems to be insufficient to clear the L1 cache (which I noticed using the memory profiler).
idle session
- Mappings cannot be reused at this time. All packages declared with "lazy = true" end with the following exception (even if the session is not closed):
Initialization [...] failed to lazily initialize the role collection: [...] the session or session is not closed
Obviously, it cannot update the mappings (they are shared with the web application) with lazy = "false", this will be a huge drawback for execution
- Cannot interact with L2 cache: when deploying a shared L2 cache, the service will not be able to invalidate the L2 cache so that the web application has fresh updated data.
NHibernate has proven its effectiveness so far, we have successfully used the state session and NHibernate LINQ in a web context, with a structural map for dependency injection.
My questions:
- Are there any good solutions for using NHibernate in a long stream?
- I would rather use a stateful session, but how do I avoid a memory leak?
source share