-->
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: How to map List in hibernate
PostPosted: Wed May 23, 2007 1:07 pm 
Newbie

Joined: Tue Dec 05, 2006 7:40 am
Posts: 14
Hi,

I was read the tutorial about parent/child map and in

http://www.hibernate.org/hib_docs/v3/reference/en/html/example-parentchild.html

he use a Set but my system I Need a List(ArrayList) but when change:
<set name="children">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>

to:

<list name="children">
<key column="parent_id"/>
<one-to-many class="Child"/>
</list>

hibernate doesn't work. hibernate says that List need add more xml elements !

how I Map this association with List instead of Set ?

thanks !

Alex


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 1:41 pm 
Beginner
Beginner

Joined: Mon May 21, 2007 5:22 pm
Posts: 27
Location: Salt Lake City
If you are using the list, then you need to define the list-index.
Because in list we have the indexing property.

So now you can try with this.

<list name="children">
<list-index column="children_index"/>
<key column="parent_id"/>
<one-to-many class="Child"/>
</list>

Enjoy !!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 8:50 pm 
Newbie

Joined: Thu May 17, 2007 11:27 am
Posts: 8
Location: US
rahul dongre is right. You need to add the list-index column to the xml file which define the primary key column in your table. Also, if your table has more than one key you can use composite key.

_________________
Raemond


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 9:37 pm 
Newbie

Joined: Tue Dec 05, 2006 7:40 am
Posts: 14
rahul dongre wrote:
If you are using the list, then you need to define the list-index.
Because in list we have the indexing property.

So now you can try with this.

<list name="children">
<list-index column="children_index"/>
<key column="parent_id"/>
<one-to-many class="Child"/>
</list>

Enjoy !!


ok,thanks... but What it do ?

because I add

<list-index column="something" />

and I not have any column called something ! and works, I can put anything column ? and work.

the documentation says:

column_name (required): The name of the column holding the collection index values.

why I need it ?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 9:11 am 
Newbie

Joined: Thu May 17, 2007 11:27 am
Posts: 8
Location: US
list-index column just like the primary key column in your table.
For example, if you have two tables like the following
Parent(
ParentId int Primary key,
FName,
LName
)

Child(
ChildId int Primary key,
ParentId int,
FName,
LName
)

Then Child Id is the List-index which make each element in your list is unique.

_________________
Raemond


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 11:17 am 
Beginner
Beginner

Joined: Mon May 21, 2007 5:22 pm
Posts: 27
Location: Salt Lake City
[quote]the documentation says:

column_name (required): The name of the column holding the collection index values.

why I need it ?[/quote]

Hi,

Indexing is required by java, not defined by hibernate.

When we look back to core java collection API, we need the index for the list. Based on the index on the list we can perform various operations.

I hope you got the point.

If you need any help do let me know.

Thanks
Rahul


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.