-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem using <list> instead of <bag> when mapping a collect
PostPosted: Mon Jul 06, 2009 3:27 pm 
Newbie

Joined: Fri Jun 19, 2009 9:47 am
Posts: 3
Hi community,
I'm using Hiernate 3 with Spring 2.5.5 and here is my problem:
When mapping a collection in hibernate I have no problem using a <bag> tag in my mapping file:
Quote:
<hibernate-mapping>
<class catalog="experimentdb" name="model.SetUp" table="set_up">
<id name="setUpId" type="java.lang.Integer">
<column name="set_up_id"/>
<generator class="identity"/>
</id>
<property name="date" type="timestamp">
<column length="19" name="date" not-null="true"/>
</property>
<property name="status" type="string">
<column length="32" name="status" not-null="true"/>
</property>
<bag inverse="true" name="setUpFeatures">
<key>
<column name="set_up_id" not-null="true"/>
</key>

<one-to-many class="model.SetUpFeature"/>
</bag>
</class>
</hibernate-mapping>


but if I try to use a <list> tag, the SetUpFeature collection is not loaded properly,
it contains many empity objects.
For example, if the collection should contain 3-4 elements, if I try to swith to <list> the method
public java.util.List getSetUpFeatures()
will return 18-20 elements of wich 16 will be empty.
What I do is just to substitute the <bag> tag with the following:

Quote:
<list inverse="true" name="setUpFeatures">
<key>
<column name="set_up_id" not-null="true"/>
</key>
<list-index column="set_up_feature_id" />
<one-to-many class="model.SetUpFeature"/>
</list>


I tried to use the <set> tag and it works as well, but I need a ordered without duplicates list.
Does anyone have any ideas?

Sorry for my poor english
many thanks for the help


Top
 Profile  
 
 Post subject: Re: Problem using <list> instead of <bag> when mapping a collect
PostPosted: Tue Jul 07, 2009 11:13 am 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
make sure that your index column does not point to an existing column:
Code:
<list-index column="set_up_feature_id" />


is 'set_up_feature_id' the id of SetUpFeature?
if so try with:
Code:
<list-index column="set_up_idx" />


Christophe


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