-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping Dictionary Containing Lists
PostPosted: Wed Jul 04, 2007 4:22 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 2:55 am
Posts: 21
Hibernate version:1.2
Name and version of the database you are using: SQL Server 2005

I’ve got a mapping problem that I’m hoping someone can help me with. At the database level we have this structure:

PartyRole
PartyRoleID (PK)
PartyRoleTypeID

PartyRelationship
PartyRelationshipID (PK)
ConsumerPartyRoleID (FK)
PartyRelationshipTypeID
ProducerPartyRoleID (FK)
...

As you can see from this the PartyRelationship links two PartyRoles, and each PartyRole can be involved in multiple relationships.

In the domain we were hoping to represent it as the PartyRole having two dictionaries:

private IDictionary<PartyRelationshipKind, IList<PartyRelationship>> _producerRelationships;
private IDictionary<PartyRelationshipKind, IList<PartyRelationship>> _consumerRelationships;


The dictionary is indexed by the PartyRelationshipTypeID (from the PartyRelationship table) and the value should be the collection of relationships of that type that the role is involved in.

We wanted to use a dictionary rather than an IList as we thought it could be faster. For example if you want all the relationships of type X that the role is involved in we don’t want to have to load up and then iterate through all of the relationships, as it could be quite costly.

The problem is that there is no obvious way to map this, I’ve tried this:

<map name="ProducerRelationships" cascade="none" access="nosetter.camelcase-underscore" generic="true" lazy="true">
<key column="ProducerPartyRoleID" />
<index column="PartyRelationshipTypeID" type="PartyRoles.PartyRelationshipKind, Parties.Domain"/>
<one-to-many class="PartyRelationship" />
</map>


Unsurprisingly this doesn’t work, I’m expecting NHibernate to understand that the key column (ProducerPartyRoleID) will bring back multiple values of type PartyRelationship which should be put in a list and stored in the dictionary. When I run code with this mapping I get this sort of error:

NHibernate.MappingException: Unknown entity class: System.Collections.Generic.List`1[[PartyRoles.PartyRelationship, Parties.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].

So what I’m wondering is whether there is a way to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 04, 2007 3:14 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
I'm also interested in this issue, since I've just the same 'structure'. (A dictionary containing another dictionary).
However, I've worked around this, by creating another class, which holds the other List.
So, instead of this:
Code:
private IDictionary<int, List<string>> _elements;

I have done this
Code:
private IDictionary<int, ItemCollection> _elements

where the ItemCollection class, contains another List.

But now however, I experience another problem with this; when I run my program, NHibernate complains that it could not compile the mapping document.
It says 'error mapping generic collection ... expected one generic parameter, but found 2' :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 9:49 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 2:55 am
Posts: 21
I've added a JIRA issue for this:

http://jira.nhibernate.org/browse/NH-1065


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 10:04 am 
Newbie

Joined: Mon Aug 06, 2007 9:40 am
Posts: 2
I have a similar problem too.

In the database I have the following tables:

Person <- PersonAddress -> Address

A person can have several addesses, so PersonAddress links a person to an address with the type of address, and dates that the address was valid.

In the domain model, my person class contains a dictionary, with the address type as the key and an AddressTemporalCollection object as the value. The AddressTemporalCollection object also contains a dictionary, with the start date of the address as the key, and the address as the value.

Is it possible to map nested collections such as this?


Top
 Profile  
 
 Post subject: Re: Mapping Dictionary Containing Lists
PostPosted: Sat Jun 23, 2012 3:34 am 
Newbie

Joined: Sat Jun 23, 2012 3:23 am
Posts: 1
very usefull for us…thanks.


english dictionary


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