Thank you for your answers !

I found this page at about the same time : https://www.hibernate.org/193.html
It basically says the same : use a property to "get" the index of the
item manually.

On 20 nov, 16:30, Roger Kratz <[email protected]> wrote:
> Using bidirectional refs in indexed collections are a bit tricky.
>
> When you say inverse=true, you tell nhib to ignore that side of the 
> relationship. I normal model the index is part of the collection, and this 
> part you tell nhib not to use (inverse=true).
>
> you need to add something like (pseudo, from my head) this in the child 
> mapping ("readonly" is new in 2.1 - suits fine for this)
> <property name="CollectionIndex" access="readonly" 
> [column=sameAsDbColumnForCollectionIndex]/>
>
> ...and then fix it your model, something like this...
>
> class Post
>    int CollectionIndex
>    {
>       get { return Blog.Posts.IndexOf(this); }  
>       //or similar - just find out what pos this instance have
>    }
>
> /Roger
>
> ________________________________________
> Från: mathieu [[email protected]]
> Skickat: den 20 november 2009 14:58
> Till: nhusers
> Ämne: [nhusers] Re: Changing index order in list mapping.
>
> Yes, I do.
> If I remove the "inverse=true", updates are issued :
>
> UPDATE POST SET ID_BLOG = null, ORDER = null WHERE ID_BLOG = @p0 AND
> ID_POST = @p1
> But it doesn't work as ID_BLOG is not nullable on DB side...
>
> If I remove the db constraint, everything is fine. But it's not very
> clean :)
> It seems the inverse attribute is causing trouble, but I can't find
> where...
>
> On 20 nov, 14:43, "c.sokun" <[email protected]> wrote:
>
>
>
> > Have you flush your session?
>
> > On Nov 20, 8:12 pm, mathieu <[email protected]> wrote:
>
> > > Hello everyone,
>
> > > I have a Blog class, that has a <list> of Post in it. I can't manage
> > > to update only the order, like this :
>
> > > Post temp = myBlog.Posts[idx];
> > > myBlog.Posts.Remove(temp);
> > > myBlog.Posts.Insert(idx + 1, temp);
> > > mySession.Save( myBlog );
>
> > > When I do this, no update is issued, and the new order is not
> > > persisted.
> > > Am I doing something wrong ? Or shouldn't I use an indexed list for
> > > this purpose (defining an order). I also tried swapping the two
> > > elements (without removal), with no success.
>
> > > Thanks.
>
> > > PS. The mapping is like this :
> > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> > >     assembly="Blog"
> > >     namespace="Blog.Entities">
> > >   <class name="Blog" table="BLOG" >
> > >     <id name="Id" type="System.Int64" column="ID_BLOG">
> > >       <generator class="increment"/>
> > >     </id>
> > >     <list name="Posts" cascade="all" table="POSTS" inverse="true" >
> > >       <key column="ID_BLOG" />
> > >       <index type="System.Int32" column="ORDER" />
> > >       <one-to-many class="Post"/>
> > >     </list>
> > >   </class>
>
> > >   <class name="Post" table="POST" >
> > >     <id name="Id" type="System.Int64" column="ID_POST">
> > >       <generator class="increment"/>
> > >     </id>
> > >     <many-to-one name="Blog" column="ID_BLOG" class="Blog" not-
> > > null="true" />
> > >   </class>
> > > </hibernate-mapping>
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/nhusers?hl=.

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=.


Reply via email to