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 a IDictionary into a IList of Entities
PostPosted: Wed Dec 20, 2006 9:48 am 
Newbie

Joined: Wed Dec 20, 2006 9:00 am
Posts: 10
Location: Brazil (GMT-3)
Hi! I'd like to map a very weird association. I want to access a list of entities through a string key of a dictionary. Does anyone have a good suggestion of mapping for that?

I think probably I'll have to use an intermediate entity to accommodate that, but I also believe that doing it in such way will generate a ugly underling database.

Has some one come across that before?

Thanks,
Luis


Top
 Profile  
 
 Post subject: Re: Mapping a IDictionary into a IList of Entities
PostPosted: Wed Dec 20, 2006 9:56 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
luismalheiro wrote:
Hi! I'd like to map a very weird association. I want to access a list of entities through a string key of a dictionary. Does anyone have a good suggestion of mapping for that?


Have You looked at <map> mapping? AFAIK it is used to map dictionaries.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: Re: Mapping a IDictionary into a IList of Entities
PostPosted: Wed Dec 20, 2006 10:27 am 
Newbie

Joined: Wed Dec 20, 2006 9:00 am
Posts: 10
Location: Brazil (GMT-3)
gert wrote:
Have You looked at <map> mapping? AFAIK it is used to map dictionaries.

Gert


Yes, I have. It's quite easy to use the <map> to map a string into an entity,

Code:
<map name="Parameters">
      <key/>
      <index type="String"/>
      <many-to-many class="Parameter"/>
</map>


but what I need is

IDictionary --> IList --> Entity

and not

IDictionary --> Entity

I thought about a <composite-element> or a <index-many-to-many> associated with <map>, but couldn't make it in the way I want...
Thinking about VB.NET, I'd like to access the property in a way like this:

Code:

   EntityB = EntityA.Parameters("KEY_NAME)(0)




That is: EntitiA.Parameters returns an IDictionary and EntityA.Parameters("KEY_NAME) returns a IList and finally EntityA.Parameters("KEY_NAME)(0) returns the entity EntityB. Of course, there may exist lot's of casts (CType's) in that expression, but I can cope with that.

I was thinking... Is there a topic in weird associations in this forum? :-)


Top
 Profile  
 
 Post subject: Re: Mapping a IDictionary into a IList of Entities
PostPosted: Wed Dec 20, 2006 10:39 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
luismalheiro wrote:
That is: EntitiA.Parameters returns an IDictionary and EntityA.Parameters("KEY_NAME) returns a IList and finally EntityA.Parameters("KEY_NAME)(0) returns the entity EntityB. Of course, there may exist lot's of casts (CType's) in that expression, but I can cope with that.

I was thinking... Is there a topic in weird associations in this forum? :-)


Ok, now I got it. Maybe the simplest solution would be to build that dictionary using .Net code, and not to map it with NHibernate? And let the primary (mapped) association do be simple <bag> or <set>?

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: Re: Mapping a IDictionary into a IList of Entities
PostPosted: Wed Dec 20, 2006 11:32 am 
Newbie

Joined: Wed Dec 20, 2006 9:00 am
Posts: 10
Location: Brazil (GMT-3)
gert wrote:

Ok, now I got it. Maybe the simplest solution would be to build that dictionary using .Net code, and not to map it with NHibernate? And let the primary (mapped) association do be simple <bag> or <set>?

Gert


At least now I'm reasonably sure that there isn't a simple mapping for that. I'll try to sort it with some extra lines of code then.

Thanks, Gert!

Luis


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.