-->
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.  [ 4 posts ] 
Author Message
 Post subject: NHibernate collection...
PostPosted: Tue Aug 30, 2005 4:27 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Here's a newbie question: How to I choose between Set and Bag? Thanks!

Reference: http://www.google.ca/url?sa=t&ct=res&cd=3&url=http%3A//nhibernate.sourceforge.net/nh-docs/en/html/chunk/ch04.html&ei=7hcUQ8PUIsT64AGNivH8DQ


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 6:24 am 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
The main difference is that a set doesn't allow duplicate objects where a bag does allow that. Therefore a set is more efficient.
The problem though, is that a set is not available in the .NET class library. Therefore you have to choose between using an 3rd party library for sets (Iesi.Collections) or just use ILists for bags.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject: Sets Vs Bags and Collection mapping
PostPosted: Wed Aug 31, 2005 5:22 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Hey thanks ...

Quote:
Therefore you have to choose between using an 3rd party library for sets (Iesi.Collections) or just use ILists for bags.


So,...
1. What do I use for Sets? (IList for bags... What for Sets?)
2. IList for bags... okay, but I'd need NHibernate.dll as well...
From doc...
Quote:
Namespace: NHibernate.Collection
Assembly: NHibernate (in NHibernate.dll)


Am I right? That you can't use dot-net framework "System.Collections.ICollection" for "sets" or "bags"?

3. When I look over doc for "Iesi.Collections" I found total of 8 collection types:
a. Hashset
b. DictionarySet
c. HybridSet
d. ImmutableSet
e. ListSet
f. SortedSet
g. Set
h. SynchronizedSet

And just ONE interface - "ISet"...

When do I use what?? I suppose it depends on my collection type specified in my mapping file right? But also from doc (http://nhibernate.sourceforge.net/nh-do ... ollections), you can specify either:
1. Set
OR
2. Bag

....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:57 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
Hi guys,
I have had simmilar dillema some time ago, so I dare to join your discussion ;)
As the FAQ is saying - use IList with Bag and Iesi.Collections.ISet with set - NOT the particular implementations (SortedSet, HybridSet, ArrayList, etc), interfaces only. When fetching a persistent object from session NHibernate will attach its own "proxy" implementation of the collection - sorted version if "sort" was specified in the mapping or unsorted in other case. If you are working for example with a new ("transient") instance of persistable object, temporarly attach SortedSet or HybridSet to Set collection on ArrayList or SortedList to Bag collection and NHibernate will swap it with his implementations during save (personally I prefer attaching new concrete collection in a property getter).

Generally I suggest using "Sets" in most cases, as they fits best with typical one-to-many or many-to-many relations (for example OrderLine exists once in Order.Lines collections, Role exists once in User.Roles collection etc.) and they are equally effective regardless you specify inverse=true/inverse=false.
I can see two advantages for "Bags" - obviously when you need object duplicates in the collection (Icon object in IconBar.Icons collection ?) or - the one I discovered recently - if you are adding an object to lazy-initialized Bag, there is no need for NHibernate to initialize the Bag, so it can be usefull with some huge collections ( LogEntry object -> Application.Log colection ?)

_________________
michal


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