-->
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.  [ 7 posts ] 
Author Message
 Post subject: Set or Bag?
PostPosted: Sun Sep 30, 2007 8:07 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
In the world of NHibernate usually usage of Sets are encouraged. But bags have one advantage. When you add an Item to a bag, it does not load all the items from db. In the case of set it will load entire set in order to add your new item.

Yes I know we can only initiate the non-inverse side but that doesn't seem a pleasant solution. Instead why not use bags ?

Considering there might be too many items in the bag in future, I feel relying on bags by default rather than sets is a safer bet. What do you think ?


Top
 Profile  
 
 Post subject: Re: Set or Bag?
PostPosted: Sun Sep 30, 2007 9:10 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
emperon wrote:
But bags have one advantage. When you add an Item to a bag, it does not load all the items from db. In the case of set it will load entire set in order to add your new item.

I would be surprised if that were true.

I would have thought that the purpose of a Set is to ensure that all items in the collection for the current session are unique, before persisting.


Last edited by PandaWood on Sat Jul 12, 2008 10:47 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 9:16 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
http://www.hibernate.org/hib_docs/nhibe ... ialization

As you see from docs this is true!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 9:23 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
Hi emperon,

What text in that doco makes you think that all existing rows in the database are loaded, if a collection is mapped as a Set?


Last edited by PandaWood on Sat Jul 12, 2008 10:45 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 9:35 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, sets need to initialize themselves if you want to add an item since they must return true/false depending on whether the add succeded.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 9:46 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
PandaWood, It is in 15.5.3.

So why not using bags by default ? Why nhibernate community promotes sets instead of bags despite of this ? What other disadvantages bag s have over sets ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 9:56 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
One possible disadvantage of bags, is that you can't eager-fetch two collections of bags at the same time.


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