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.  [ 6 posts ] 
Author Message
 Post subject: Reorder the index property in a list?
PostPosted: Mon Oct 24, 2005 10:44 am 
Newbie

Joined: Tue Oct 04, 2005 6:52 pm
Posts: 6
I am trying to figure out a way to do this:

A parent object with a collection (list) of children. The children have an "order_id" column that is 0-x in value. The parent and child are double mapped (the parent has a collection of children, the child has a reference to the parent via many-to-one). I have cascade set as "all-delete-orphan". Becuase of what the documentation says on two way mapping, the child collection property on the parent is marked with inverse="true".

The problem I am having is that if I remove an item from index 0 and insert it at the end (reorder the list, moving the child from first to last), the changes are never preserved in the database. I am not sure if this is due to the inverse flag or a lack of functionality with the list implementation.

Right now I had to implement a bad hack, where I made order_id a mapped property on my child object and made changes that way. This is very klugy as I then have to reorder the list in memory every time someone changes the order property on an item in the list.

Is there a solution to this? I really need this functionality, as the order of the children in my list has business meaning.

_________________
Thanks,
Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 3:54 pm 
Newbie

Joined: Tue Oct 04, 2005 6:52 pm
Posts: 6
I am still waiting for a response on this. If I don't hear back soon, I will try to report a bug with collections not being saved correctly.

_________________
Thanks,
Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 4:00 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It is already reported as a bug. This is Hibernate 2 limitation - inverse="true" means that the child entity handles the association, and the child entity doesn't have any means of knowing its index in the parent's collection, so lists (and maps) can't be used with inverse.


Top
 Profile  
 
 Post subject: Workaround suggestions?
PostPosted: Tue Jun 06, 2006 10:48 pm 
Newbie

Joined: Tue Jun 06, 2006 10:45 pm
Posts: 5
What is the suggestion here for a workaround?

Is there a way to affect the same relationship/mapping without using inverse=true? or is the answer to explicitly iterate over all the children like this:

foreach(Child child in Parent.Children)
session.Update(child);

or what?

I'm curious what people have come up with on this.
Ian


Top
 Profile  
 
 Post subject: workaround... for now...
PostPosted: Wed Jun 07, 2006 8:11 am 
Newbie

Joined: Tue Jun 06, 2006 10:45 pm
Posts: 5
The workaround described here:

http://www.hibernate.org/193.html

works well for me in NHibernate despite admonitions about problems associated with lazy loading. As a precaution, I'm using NHibernateUtil to explicitly initialize collections before doing order modifications on them.

Ian


Top
 Profile  
 
 Post subject: using index with list
PostPosted: Wed Jul 05, 2006 8:41 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
I gone through ur post, actually i have the same problem, can u tell me what is the solution in details, i m using Nhibernate 1.0.2, do i need to create property on client side also.


I m posting that piecie of the mapping which has <list> mapping.
I want to swap the object position which should be reflected in the database.

Plz if possible give the detailed workaound. I m not clear from the link u have posted

<list name="Nodes" lazy="true" cascade="all-delete-orphan" inverse="true " >
<key column="ParentID" />
<index column="Pos" />
<one-to-many class="MyNewBagHierarchyWork.NodeRelation, MyNewBagHierarchyWork" />
</list>


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