-->
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: which to use in one to many relation Set or list
PostPosted: Tue Mar 16, 2010 7:59 am 
Newbie

Joined: Thu Mar 17, 2005 5:50 am
Posts: 12
I have a question in one to many relation

in the entity class when to use Set and when to use List

and what is the difference and effect on hibernate performance


Top
 Profile  
 
 Post subject: Re: which to use in one to many relation Set or list
PostPosted: Tue Mar 16, 2010 9:55 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Set per definition cannot hold duplicate entries
furthermore it does not preserve the order as its elements are not indexed.

List per definition can hold duplicate entries (which for mapping relations has poor sense: associate a certain couple of objects twice over the same relation) and preserves the order as its elements are indexed.

On hibernate performance I would say that there is no significat performance difference between them (beside the fact that list needs an extra index field on schema)
On Java-level set.contains(obj) is sure much more performant as list.contains(obj) because ladder must do a sequential scan.

Hibernate documentation generally suggests Set.
In my opinion Set reflects more that what under UML is intended as relation.
Use List if you need that the order in which the elements were associated must be preserved or if you wish
to access the associated elements per index (list.getAt(index))


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.