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.  [ 3 posts ] 
Author Message
 Post subject: Preferred collection interface: Set or List?
PostPosted: Wed Apr 18, 2007 4:22 pm 
Newbie

Joined: Wed Apr 18, 2007 4:10 pm
Posts: 3
For associated collections (that can e.g. be cascaded to) the preferred collection interface seems to be Set (mapped using the <set/> tag). The rationale being that Sets are closest to the relational model.

For collections returned from queries, however, the only choice seems to be a List (or an Iterator). This doesn't seem consistent, but there may be a good reason, which has just escaped me so far. I may also be missing something.

In any event, I appreciate any clarifications ;-) I am suggesting changes to our current persistence architecture choices (using Hibernate, of course), and need as many facts as I can get. (This is a big project...)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 4:37 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Queries can return Lists of entities (or Lists of Object[] if projections are used), not the associated collections as Lists. Using Lists when mapping collection associations is only applicable where the collection is ordered by an index column contained in the table itself. And preferably, the index column is contiguous (no gaps in the numbers), and starts with 0 (zero).


Top
 Profile  
 
 Post subject: Re: Preferred collection interface: Set or List?
PostPosted: Wed Apr 18, 2007 4:41 pm 
Beginner
Beginner

Joined: Fri Apr 13, 2007 9:27 am
Posts: 33
carlos.l.sanchez wrote:
For associated collections (that can e.g. be cascaded to) the preferred collection interface seems to be Set (mapped using the <set/> tag). The rationale being that Sets are closest to the relational model.

For collections returned from queries, however, the only choice seems to be a List (or an Iterator). This doesn't seem consistent, but there may be a good reason, which has just escaped me so far. I may also be missing something.

In any event, I appreciate any clarifications ;-) I am suggesting changes to our current persistence architecture choices (using Hibernate, of course), and need as many facts as I can get. (This is a big project...)


I am new to Hibernate as well, and here is how I understand it.
when you map a collection, it is based on one-to-many, many-to-one, or many-to-many, in any case there is relations between the database tables
"Referational integrity". Elements in a SET are unique, and hence it insure that every element in the set is unique. It reflects the Referational Integrity of your database.

When you query the database, the result is not neccesserly unique. One might allow same data rows to exist more than once. In addition, you might query for some attributes duplication of data is possible.


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