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.  [ 1 post ] 
Author Message
 Post subject: NHibernate child objects not reflecting changes or refresh
PostPosted: Mon Dec 15, 2008 5:55 am 
Newbie

Joined: Mon Dec 15, 2008 5:45 am
Posts: 1
DUPLICATION NOT INTENDED.

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.

Originally posted: http://stackoverflow.com/posts/edit/367119

Was advised to post here.


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

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.