-->
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.  [ 5 posts ] 
Author Message
 Post subject: Can I Dispose IQuery objects Like Enumerables?
PostPosted: Tue Jan 15, 2008 12:48 pm 
Newbie

Joined: Sun May 14, 2006 8:48 am
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.2.0.4000

Full stack trace of any exception that occurs:
Stack trace: at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Type optionalEntityName, Object optionalIdentifier, IEntityPersister persister)
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)
at NHibernate.Impl.SessionImpl.ImmediateLoad(Type clazz, Object id)
at NHibernate.Proxy.LazyInitializer.Initialize()
at NHibernate.Proxy.CastleLazyInitializer.Intercept(IInvocation invocation, Object[] args)
at CProxyTypeMehan_Navand_EntityLayer_ContentManagementContentEntityContentManagement_NHibernate_ProxyINHibernateProxy1.get_TopTitle()
at DisplayControl.Page_Load(Object sender, EventArgs e) in e:\Projects\Navand\Development\Website\UserControls\Display.ascx.cs:line 172
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Name and version of the database you are using:
SQLExpress 2005


Problems with Session and transaction handling? ok

I use NHibernateSessionModule as ASP.NET module for holding NH Sessions for each request separately, plus i do not create threads.
also all of my queries executed using ISession.CreateQuery().List()
(i.e. i use IQuery.List())
but some times (that i did not know where and when - some times in transparent initializing lazy loaded collection and above StackTrace is "try to get proxy property") an error with below message occurs:


There is already an open DataReader associated with this Command which must be closed first.


this error will be shown if 2 IDataReader try to get data from a connection at once
previously i used IQuery.Enumerable() in try catch block and dispose result enumerable in finally block:

Code:
finally{
    ((IDisposable)enumerable).Dispose();
}


this coding style will not generate above error, but will create very queries, so i switched to IQuery.List() method

my question is:
how can i dispose IQuery object? (for closing underlying IDataReader or SqlDataReader object)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 3:27 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
Hmmm, when does this happen, can you provice some code between opening your session and closing the session that will result in this behaviour?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 4:05 pm 
Newbie

Joined: Sun May 14, 2006 8:48 am
Posts: 12
Thanks for reply,
But i did not know where and when this error will generated.
i have a page, in almost every time all things are ok, but in production server that more than 150 users are online, this error was generated.
also not all errors of this type generated at this page.

below is code:

Code:
if (String.IsNullOrEmpty(StoryId))
         return;
      if (ClearCache)
         Cache.Remove(StoryId);
      item = NoCacheUse ? null : Cache.Get(StoryId) as ContentEntity;
      if (item == null) {
         [b]item = ContentBusinessLayer.Instance.Load(StoryId);[/b]
         if (item == null)
            return;
         Cache.Add(item.Id, item, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null);
      }

// some times error generated here from a proxy

      TopTitle.InnerHtml = item.TopTitle;
      TopTitle.Visible = true;

      IconImage.ImageUrl = item.Icon;
      IconImage.Visible = true;

      ContentTitle.InnerHtml = item.Title;
      ContentTitle.Visible = true;

      SubTitle.InnerHtml = item.SubTitle;
      SubTitle.Visible = true;

      ContentLead.InnerHtml = item.Lead;
      ContentLead.Visible = true;

      ContentBody.InnerHtml = item.Body;
      ContentBody.Visible = true;

      Page.Title = item.PageTitle;

      PublishTimeLabel.Text = item.PublishTime;

// and some times error generated here
      LabelsPanel.Visible = item.Labels.Count>0;
      if (LabelsPanel.Visible) {
         LabelsRepeater.DataSource = item.Labels;
         LabelsRepeater.DataBind();
      }

      Helper.SetKeywords(Page.Header, item.Keywords);
      Helper.SetDescription(Page.Header, item.Description);

      
      if (SourcePanel.Visible) {
         SourceHyperLink.Text = item.SourceName;
         SourceHyperLink.NavigateUrl = item.SourceUrl;
      }


but please note:
1. almost everything is ok
2. in pages other than above this error may be generated (i put this just as sample)
3. i simplify the code, line that i try to blod, i.e. "ContentBusinessLayer" is loader function.

below is hbm of entity:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Mehan.Navand.EntityLayer.ContentManagement" assembly="Mehan.Navand.EntityLayer">
   <class name="ContentEntity"   table="OrmCms_ContentsTable" select-before-update="true" dynamic-update="true" optimistic-lock="none">
      <id name="Id" type="string" unsaved-value="null">
         <generator class="uuid.hex" />
      </id>
      <version name="Version" unsaved-value="-1"/>
      <property name="CreationDate" type="datetime"/>
      <property name="DisplayIcon" />
      <property name="Icon" />
      <property name="DisplayTopTitle" />
      <property name="TopTitle" />
      <property name="DisplaySubTitle" />
      <property name="SubTitle" />
      <property name="Body" type="StringClob" />
      <property name="Title" />
      <property name="DisplayTitle" />
      <property name="Lead" type="StringClob" />
      <property name="DisplayLead" />
      <property name="PageTitle" />
      <property name="ChangePageTitle" />
      <property name="Layout" />
      <property name="Url" />
      <property name="DisplayLabels" />
      <property name="DisplayRelatedContents" />
      <property name="DisplaySourceLink" />
      <property name="SourceName" />
      <property name="SourceUrl" />
      <property name="ContentType" />
      <property name="Comment" />
      <property name="Description" />
      <property name="UseDescription" />
      <property name="Culture" />
      <property name="IsPermanent" />
      <property name="Importance" />
      <property name="DisplayLastModified" />
      <property name="LastModified" type="datetime" />
      <property name="PublishTime" type="datetime" />
      <property name="VisitedCount" type="int" />
      <property name="DisplayLinkers" />
      <many-to-one name="Creator" column="CreatorId" class="Mehan.Navand.EntityLayer.MemberEntity" not-null="true"/>
      <bag name="Labels" table="OrmCms_ContentLabelsTable">
         <key column="ContentId"/>
         <element column="Label" type="string"/>
      </bag>
      <bag name="Keywords" table="OrmCms_ContentKeywordsTable">
         <key column="ContentId"/>
         <element column="Keyword" type="string"/>
      </bag>
      <bag name="RelatedContents" table="OrmCms_ContentRelatedContentsTable" lazy="true">
         <key column="ContentId"/>
         <many-to-many class="ContentEntity" column="RelatedContentId"/>
      </bag>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 4:13 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
Could it be that you place the persistent object in cache, and when the cache is hit and lazyloading is supposed to happen the session is gone because it is associated with a single request


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 4:26 pm 
Newbie

Joined: Sun May 14, 2006 8:48 am
Posts: 12
Let me test it


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.