-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problem with List, when Set works fine
PostPosted: Sat Oct 18, 2003 11:58 am 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
I have a collection of a Set that works fine, but when I convert it to a List it throws a NP Exception when iterating over the objects. Dubugging it it looks like the Object is good and well until I cast it with the Iterator.next(). I am using H2-Beta4. Here are my mappings:

WORKS:
-----------

<set name="inventoryHistories" cascade="all" lazy="true">
<key column="product_id"/>
<one-to-many class="com.ldi.db.hibernate.InventoryHistory"/>
</set>

DOESN'T WORK
-------------------

<list name="inventoryHistories" cascade="all" lazy="true">
<key column="product_id"/>
<index column="inventory_history_id"/>
<one-to-many class="com.ldi.db.hibernate.InventoryHistory"/>
</list>

TEST CODE
--------------

Product p = (Product) s.load(Product.class, new Integer(1205));

assertNotNull(p.getInventoryHistories());
assertTrue(p.getInventoryHistories().size() > 0);

Iterator it = p.getInventoryHistories().iterator();
while ( it.hasNext() )
{
InventoryHistory ih = (InventoryHistory) it.next();
assertNotNull(ih); <--- FAILS
}



I know it's gotta be something simple, I have been staring at it too long. Any help is appreciated. Thanks.

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2003 1:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I notice that you are trying to use inventory_history_id as the index of the List. I'm going to further guess that inventory_history_id is the PK into the InventoryHistory class. Thats not the purpose of the index attribute on list. The index attribute specifies property Hibernate should use to position the items within the List. So you are most likely experiencing "gaps" within your List.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2003 2:13 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
Steve:

How correct you are. Thanks. Quick question if you have time, does the index column have to be a number, can it be a date? I am trying to convert a legacy system and the only thing I can order_by is the create_Date but that does not seem to be working. Thanks.

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2003 2:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well it has to be a int to satisfy the java.util.List contract.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2003 2:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Another thought is that that index element accepts a type attribute. You might try a UserType impl. The issue is that the index values need to be sequential ints for the given relation


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 10:30 am 
Newbie

Joined: Wed Oct 15, 2003 4:31 pm
Posts: 17
steve wrote:
I notice that you are trying to use inventory_history_id as the index of the List. I'm going to further guess that inventory_history_id is the PK into the InventoryHistory class. Thats not the purpose of the index attribute on list. The index attribute specifies property Hibernate should use to position the items within the List. So you are most likely experiencing "gaps" within your List.


Howdy,

It appears that all the docs on using Lists I've seen say that the index property in the mapping file is supposed to be a column name. But above you say it's supposed to be a property name. While I realize that properties map to columns, I guess I'm finding this confusing.

Is the mapping files <index column="x"/> supposed to describe the actual column name in the "child" table or is it meant to be the name of a property that manages an index value for the child class?

Thanks!

Gerry


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 10:58 am 
Newbie

Joined: Wed Oct 15, 2003 4:31 pm
Posts: 17
Actually, I think I've answered my question - the column= is in fact the name of the column in the "child" table that the index is in.

I think what was throwing me was that I expected hibernate to completely manage this column and I now beleive it doesn't.

From what I'm reading, the column is used in a read-only fashion by hibernate. You have to insure the correct value is in the column. Hibernate will not populate it when saving out the parent with the List collection in it.

Is this a fair assessment of Lists and the column= attribute in the mapping file?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 1:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is correct iff inverse="true".


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 3:06 pm 
Newbie

Joined: Wed Oct 15, 2003 4:31 pm
Posts: 17
gavin wrote:
This is correct iff inverse="true".


Thanks - I'm starting to get most of this now :-)


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