3

I have an object that called 'category' and the table looks like this.

CATEGORY
-------------------------------------------------
ID                 int  
ParentCatalogID    int  
ParentCategoryID   int << This is the ID of this table 
Position           int  
Title              nvarchar(128)    
Description        nvarchar(1024)   
LastUpdated        datetime 
DateCreated        datetime 
IsActive           bit  

Everything works as normal when insert, update, delete etc... The mapping is fine.

The data from this table is rendered into a html list that is 'nested' (hence the self referencing). This all renders beautifully.

When the Position is updated (move up || move down) the updated list reflects the change and the list item in question moves its position in the list.

The problem is when the ParentCatalogID is changed (move left || move right to become a child of the above list entry). The data passed through to the list render method is not reflecting the change UNTIL the page is refreshed by pressing F5, clicking refresh (reloading the page).

This will give you a basic idea of how:

foreach (nc_Category category in root.nc_Categorys)
{
  HtmlControl listItem = BuildListItemFromCategory(category);
  if (category.nc_Categorys.Count > 0)
      {
        listItem.Controls.Add(BuildListFromCategorys(category.nc_Categorys));
      }
  mainList.Controls.Add(listItem);
}

This all works fine. The problem is that in the line >> foreach (nc_Category category in root.nc_Categorys) the root.nc_Categorys (the children of the current object) does not reflect the changes made until the page is refreshed. I can see this in the debug. So NHibernate is not getting the updates when lazy loading.

The changes are committed, flushed and visible in the database. They are not retrieved by NHibernate.

I have tried Refresh() method on the object, this does not work. It is the children of the object that are required to be refreshed.

I have tried clearing the session and many other thing to no avail. This only happens when changing the ParentCategoryID. When the Position is changed they are shown immediately.

This seems similar but not sure: http://jira.nhibernate.org/browse/NH-1604

I am response.redirecting to the same page (yuk). It works fine, but it should not need it. Response very much appreciated.

stian.net
  • 3,928
  • 4
  • 25
  • 38
  • This looks rather complex, I'd suggest that you post this on the nhibernate forums (http://forum.hibernate.org/viewforum.php?f=25 or http://groups.google.com/group/nhusers) along with the simplest possible code that reproduces your issue. – Mauricio Scheffer Dec 15 '08 at 01:21
  • It looks that there aren't many NHibernate users around here, plus I find it really annoying about this site that I can't post more that 300 chars on a comment like this one, it seems that its target is simple direct questions, not specific issue troubleshooting. – Mauricio Scheffer Dec 15 '08 at 01:22

1 Answers1

0

Could it be related to different sessions being used at the different points in your app, I know the java hibernate option has a concept of using the same hibernate session for the backend servlet as well as the jsp front end stuff.

Chris Kimpton
  • 5,546
  • 6
  • 45
  • 72