Hi all,
I am using Nhibernate in my application with LAZY= true, inorder to enhance my performance of my application.In fact i was able to achieve as well, but the difference was less 5 seconds compared to earlier 13 seconds.
Well i need to understand, the real concept behind the LAZY attribute.
By the way this is the approach i am using for Opening a Session.
protected ISession _session = null;
public void OpenSession()
{
try
{
if (_sessionCreatedLocally && (_session == null || !_session.IsOpen))
{
_session = PersistenceManager.NHFactory.OpenSession();
}
catch (Exception ex)
{
throw ex;
}
}
I have maintained _session variable as local. So each and everytime I call this method opensession(), new session will created and returned to me.
I have provided explanation for the above scenario.
Please note, I am not explicitly closing the session any where in my application. HBM files will be loaded in the memory, as and when it is needed, as I am using LAZY = true. As I am not closing the session, when i query in the DATABASE using SQLProfiler, i can see lot of sessions created in my SYSTEM IP and SPECIFIC DATABASE.Since I use this.opensession() in my all transactons(save, update, search), numerous session creation happens, as and when i hit the database.
a) Is anything wrong in having lot of open sessions ?What will be the effect?
b) If i explicitly call this.closeSession(), my lazy attribute is throwing error," Unable to load the lazy attribute"
c) In some scenario,even though i did not close the session, i get "“Failed to lazy initilaize a collection". I am unable to track it.
(I am not sure, is anything to do with LARGE DATA or NETWORK Discrepancy)
d) What will happen to loaded HBM files, as and when session creates, it will keep accumulating in the memory & have duplicate copy or will it have fresh copy of HBM files in the memory.
OS: Windows
Working platform : .Net ,C#
Database : SQL server 2005
Nhibernate Version: 1.2
Please share me your thoughts.
Let me know any further clarification needed !!
Thanks for your time.
Cheers
Sudhagar.S
sudhagar76@gmail.com