These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Session and Lazy issues!!
PostPosted: Wed Sep 19, 2007 5:58 am 
Newbie

Joined: Mon Jul 16, 2007 9:39 am
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 4:52 am 
Beginner
Beginner

Joined: Thu Oct 26, 2006 4:45 am
Posts: 39
Let me change the question to you:

- Why are you trying to use multiple sessions?

The lazy attribute is for only going for a database-read if the property is actually used in your code.

If some property of your class is not used, than there is no nead to read the (child-)property from the database. NHibernate takes care of that with the lazy-attribute.

Hope this helps,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 5:09 am 
Newbie

Joined: Mon Jul 16, 2007 9:39 am
Posts: 4
hace_x wrote:
Let me change the question to you:

- Why are you trying to use multiple sessions?

The lazy attribute is for only going for a database-read if the property is actually used in your code.

If some property of your class is not used, than there is no nead to read the (child-)property from the database. NHibernate takes care of that with the lazy-attribute.

Hope this helps,


Thanks for the reply,

1) As I am using _session as NON Static variable, It is not maintained throughout the application. So for each and every transaction i check for the session value, as Session state is not maintained, its value is NULL and it is creating new session for me.

2) If i use the session as static one, I am facing another issue. That any of my co-users update or delete or save operation, those things are not reflected in the current session. So for each operations to be reflected i need to close and reopen the application. In order to avoid this I have removed the static keyword and hence it shows that I am opening multiple session, but fact is at a time I am using ONE session only.

I hope i have clarified your doubt..
Try to help me out..............

Thanks for your time.
Cheers
Sudhagar.S


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.