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: Trouble with IDictionary and <set>
PostPosted: Thu Sep 20, 2007 7:19 pm 
Newbie

Joined: Fri Sep 14, 2007 8:51 pm
Posts: 12
Location: North Carolina
When trying to do a many-to-many relationship I am having trouble with the .NET code.

If I use the non-Generic IDictionary
Code:
        public virtual IDictionary Skills
        {
            get { return _skills; }
            set { _skills = value; }
        }

I then get the error:
System.InvalidCastException: Unable to cast object of type 'NHibernate.Collection.PersistentSet' to type 'System.Collections.IDictionary'.

If I use the Generic version:
Code:
        public virtual IDictionary<int, Skill> Skills
        {
            get { return _skills; }
            set { _skills = value; }
        }

I get the error:
NHibernate.MappingException: Error mapping generic collection Doa.Domain.Entities.Profile.Skills: expected 1 generic parameters, but the property type has 2

Huh????

How do I pass one parameter to the Generic IDictionary?
More information below.

Thanks,
kellygreer1




Hibernate version:
2.2

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Doa.Domain.Entities" assembly="Doa.Domain">
<class name="Profile" table="Profiles">
<id name="Id" column="id" type="Int32" unsaved-value="-1"
access="field.camelcase-underscore">
<generator class="native" />
</id>
<property name="UserName" column="ntlogon" type="string" length="24" access="field.camelcase-underscore">
</property>
<property name="LastName" column="last_name" type="string" length="18" access="field.camelcase-underscore">
</property>
<property name="FirstName" column="first_name" type="string" length="18" access="field.camelcase-underscore">
</property>
<property name="MiddleName" column="middle_name" type="string" length="18" access="field.camelcase-underscore">
</property>

<set name="Skills" table="ProfileSkills">
<key column="profile_id" />
<many-to-many column="skill_id" class="Skill" />
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 21, 2007 12:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
You must map a <set> to an Iesi.Collections.ISet or Iesi.Collections.Generics.ISet<T>.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 21, 2007 1:01 am 
Newbie

Joined: Fri Sep 14, 2007 8:51 pm
Posts: 12
Location: North Carolina
So does that mean this guy's examples are wrong?
http://www.theserverside.net/tt/article ... NHibernate

he seems to map <set> to IDictionary

oh well - will try what you said

thanks Karl,

kellygreer1


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 21, 2007 10:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
I am afraid that the example is indeed wrong, or misleading at least. I am quite certain, as far as my own experience goes, one cannot map a <set> to an IDictionary. That is why the NHibernate needs to depend on the Iesi collection library in the first place.

_________________
Karl Chu


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.