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: No index value stored for a list with inverse="true&
PostPosted: Mon Aug 14, 2006 5:17 am 
Newbie

Joined: Thu May 04, 2006 4:23 am
Posts: 16
Location: Germany
Hi,

I have a lot of bidirectional list associations following the pattern:

Code:
<!-- parent.hbm.xml -->
      <list name="ChildType" inverse="true" table="CHILD" cascade="all" >
         <key column="FK_ID_PARENT" />
         <index column="INDEX_VALUE" type="Int32" />
         <one-to-many class="Example.ChildType, Example" />
      </list>


and:

Code:
<!-- child.hbm.xml -->
      <many-to-one name="parent" class="Example.ParentType, Example" column="FK_ID_PARENT" />


In my test code I created children objects and added them to a parent object. The foreign key to the parent was stored in every child object (data base row), BUT NOT THE LIST INDEX.

After switching the mapping to inverse="false" the list index was stored correctly in the children objects (data base rows).

It's somehow logical that inverse="true" leads to this behavior because a child object does not know its index, i.e. its position in the list.

Some time ago I read somewhere in the docu (of NHibernate or Java-Hibernate) about a solution to this problem, but I couldn't find the place with this information again.

One possible (logical) solution I could imagine would be to:
    1. define an instance variable in the child class,
    2. map this variable to the index column and
    3. set the variable's value (explicitly in the code) to the index value of the child object when the child object is added to the list.

But this is a bit cumbersome. Is there a simpler way to do it?

thanks,
mick


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.