views:

804

answers:

1

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.

A: 

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