Mapping <set> with HashSet<T> generates unecessary update on collection owner

Description

When insert:ing a new entity holding a <set>-collection, the collection is considered dirty if HashSet<T> is used - leading to an unecessary update if holding entity is versioned. If Iesi.HashedSet is used, things works as expected.

I think the attached two small tests are pretty self explaining.

Environment

None

Attachments

1

Activity

Show:

Oskar Berggren November 11, 2012 at 8:18 PM

NHibernate now targets .Net 4 and uses the BCL's ISet<T> and HashSet<T>.

Fabio Maulo November 13, 2009 at 9:40 AM

When you use a collection you have 3 classes involved and one interface:

  • PersistentCollection (the proxy)

  • The collection used inside the proxy

  • the collection in your Model class.

In the model you can use ICollection<T> but you can't assign a List<T> if you have mapped it as <set> because the rule of the collection in the Model will be completely different from the rules you said it has to NH.

When you use <set> you are saying to NH : the collection implementation will implements Iesi.ISet.
As you know HashSet<T> does not implements ISet.

What is needed is a specific PersistentCollectionType.

About NH3.0 we will see... perhaps we can release it with NET4.0 required.... perhaps.

Roger November 9, 2009 at 7:00 AM

Fabio,

Just for you to know my background...
I read somewhere (nh user list, ayende's blog etc) that <set> in 2.1 changed to work against ICollection<T> rather than iese.iset<T>. What I was not aware of was this "bug"/limitation with unnecessary update if hashset impl was used, that's why I sent this to the JIRA.

Reply to your last reply...
Do you mean having two different persistencollections for <set>? One mapping to iese.set<T> and another one mapping to icollection<t> (where user should use hashset<T> or some own impl with this behaviour)? It sounds nice but...
(I haven't really looked much at nh impl here but...) Is that really necessary? Couldn't "same"/equal logic on the collection just be based on collection's ienumerable - no matter if iesi.hashedset, hashset or whatever is used? Now when user can use a ICollection<T> for a <set>, the user can use some non-set collection without any warning anyhow.
If the latter isn't possible/too much work, it would be nice with two different persistendcollections, yes.

Also...
NH 3.0 - will it be based on .net 3.5 or 4.0 (where ISet<T> exists)?

Fabio Maulo November 9, 2009 at 5:26 AM

Roger,
For real we can implement another PersistentCollection using HashSet<T> and then you can use the ICollectionTypeFactory to use this new collection for any <set>, that is what you need ?
If yes, we can change this issue from bug to improv. or we can close this issue and you can open a new one, ok ?

Roger November 5, 2009 at 7:05 AM

Ok. I wasn't aware that the change that <set> now works with ICollection<T> was a temp change until ISet<T> (BCL 4.0) is released.

Got you. Thanks for your info.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created November 5, 2009 at 3:43 AM
Updated September 21, 2014 at 12:40 PM
Resolved November 11, 2012 at 8:18 PM
Who's Looking?