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.  [ 1 post ] 
Author Message
 Post subject: Key not present in the map collection
PostPosted: Wed Nov 12, 2008 6:43 am 
Newbie

Joined: Wed Nov 12, 2008 6:10 am
Posts: 1
Hello,
My problem occurs since the upgrade from NHibernate 1.0.2 to NHibernate 2.0.
In my container class, I have a IDictionary collection which key is an Object (MyKeyClass), and values also are objects (MyValueClass).

The problem is when I try to access one of the element of the list by the key, I get an error stating that the key is not present in the collection.
But when I look at the container class in debug mode, it seems that the collection is correctly filled.
Example: myContainerClass.m_MyList[aMyKeyClass] -> will always fail.

My code:
public class MyContainerClass
{
protected IDictionary m_MyList;
}

public class MyKeyClass
{
int id;
... // some other properties...

public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
MyKeyClass anObject = (MyKeyClass)obj;

return (id.Equals(anObject.id));
}

public override int GetHashCode()
{
return id.GetHashCode();
}
}

Mapping is like this:
<map name="MyList" cascade="all" access="field.pascalcase-m-underscore" lazy="true">
<key column="KEY_OF_CONTAINER"/>
<index-many-to-many column="KEY_OF_KEYCLASS" class="MyKeyClass"/>
<one-to-many class="MyValueClass"/>
</map>

MyKeyClass and MyValueClass are also mapped, but I don't think showing them will help here.

Also, I tried to use generic IDictionary instead, but I get the same error.
This error didn't occur with NHibernate 1.0.2

Thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.