-->
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: list collection returning wrong size
PostPosted: Tue Oct 14, 2003 8:21 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
Hi,

I'm trying to figure out a weird problem. Consider the following mapping:

<hibernate-mapping>
<class name="edu.ucsd.som.tracker.RoutingTracker" table="routing_tracker">

<id name="id" column="routing_tracker_id" type="long">
<generator class="native"/>
</id>

<!-- ... -->

<list name="stages" lazy="false" table="routing_stage" cascade="all">
<key column="routing_tracker_id"/>
<index column="routing_stage_id"/>
<one-to-many class="edu.ucsd.som.tracker.RoutingStage"/>
</list>
</class>

In sample data i'm using for testing, the "stages" collection should contain 3 items. I looked at the query Hibernate generate and it does return only three items as expected. However, if I look at the size of the list corresponding to the stages property (i.e. tracker.getStages().size() ), the size returned is not 3. Rather, it is always (seemingly) the number of highest record in the list. So if the query pulls records with numbers 3, 7, 14 from the routing_stage table, the collection size would be 14. The list would contain three correct stage items as expected (in the last three elements of the list) with the other elements set to null.

Has anyone seen this before? I'm obviously not defining something correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 7:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
looks like the expected behaviour if your index values have "gaps"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 11:04 am 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
gavin wrote:
looks like the expected behaviour if your index values have "gaps"


hmm... ok, is there anything I can do to have the collection return correct number of elements?


Top
 Profile  
 
 Post subject: separate index column
PostPosted: Wed Oct 15, 2003 11:24 am 
Newbie

Joined: Wed Oct 15, 2003 11:20 am
Posts: 6
you shouldn't use routing stage id as your list index column
create a new database column solely for hibernate to store the index


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 12:36 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
thanks. i'll give it a try.

what can I read to better understand why this was happening?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 12:50 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
never mind my last question. I figured it out. I misunderstood the meaning of "index" in this context. I actually already have a column that contains the array's index. Although, the indexes start with 1, not 0, but I can deal with this on the application leve.


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.