-->
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.  [ 8 posts ] 
Author Message
 Post subject: System.Collections.IDictionary
PostPosted: Fri Feb 10, 2006 2:39 am 
Newbie

Joined: Wed Feb 08, 2006 4:10 am
Posts: 16
Unable to cast object of type 'NHibernate.Collection.Set' to type 'System.Collections.IDictionary',

my class was:
Public Class Department
Private _id As Integer
Private _name As String
Private _classes As IDictionary
Private _professor As IDictionary

Public Property id() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property

Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property

Public Property classes() As IDictionary
Get
Return _classes
End Get
Set(ByVal value As IDictionary)
_classes = value
End Set
End Property

Public Property professors() As IDictionary
Get
Return _professor
End Get
Set(ByVal value As IDictionary)
_professor = value
End Set
End Property
End Class

when is want to get the data:
Dim depts As IList = session.CreateCriteria(GetType(Department)).List

but the error message out "Unable to cast object of type 'NHibernate.Collection.Set' to type 'System.Collections.IDictionary'"

can anyone help me with this...?


Top
 Profile  
 
 Post subject: Mapping
PostPosted: Fri Feb 10, 2006 4:20 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
How are you mapping the classes and professors. Does changing IDictionary to Iesi.Collections.ISet make it work.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 4:51 am 
Newbie

Joined: Wed Feb 08, 2006 4:10 am
Posts: 16
the mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="nhRegistration.Department, nhRegistration" table="Department">
<id name="id" column="DeptID" type="Int32">
<generator class="assigned"></generator>
</id>
<property name="name" column="DeptName" type="String(50)" />

<set name="classes" cascade="all" inverse="true" lazy="false">
<key column="DeptID"/>
<one-to-many class="nhRegistration.UniversityClass, nhRegistration"/>
</set>

<set name="professors" table="DepartmentProfessor" cascade="all" inverse="true" lazy="false">"
<key column="DeptID"/>
<many-to-many class="nhRegistration.Person, nhRegistration" column="PersonID"/>
</set>

</class>
</hibernate-mapping>

how to change IDictionary to Iesi.Collections.ISet ?


Top
 Profile  
 
 Post subject: Iesi
PostPosted: Fri Feb 10, 2006 5:10 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
just add a reference to Iesi.Collections.dll and include the namespace

using Iesi.Collections;

and then change the declaration from IDictionary to ISet. If you want to instantiate a set use HashedSet class in Iesi.Collections

It should work okay then


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 5:18 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Change IDictionary to ISet.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 5:25 am 
Newbie

Joined: Wed Feb 08, 2006 4:10 am
Posts: 16
It work!!! thanks....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 4:19 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
What can be used instead of Iesi.Collections.ISet ?
I mean is there anything in .NET 2.0 that could be used for a <set> mapping.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 1:03 pm 
Newbie

Joined: Thu Mar 02, 2006 2:50 pm
Posts: 3
I'm using Iesi.Collections.ISet to map the <set> </set>

and still have related error:System.InvalidCastException: Specified cast is not valid.


Code:
public class DUser
{
        private int       uId;
        private string  uName;
        private string  uPassword;
        private string  uEmail;

        private ISet dirs = new HashedSet();

       ..........................
       ..........................

        public ISet Dirs
        {
            set {dirs = value;}
            get {return dirs; }
        }

}



getting data:

Code:
{

IList list = null;
............
............

  String HQL_Query = "from DUser user where user.UName='balblabla' ";
  list = session.CreateQuery(HQL_Query).List();
}



Code:
<class name="Test1.DUser,Test1" table="Users">
    <id name="UId" column="Id" type="int">
      <generator class="increment"/>
    </id>
    <property name="UName"      column="Name"  type="String" length="40"/>
    <property name="UPassword"  column="Pass"  type="String" length="20"/>
    <property name="UEmail"     column="Email" type="String" length="40"/>
   

      <set name="Dirs">
        <key column="uID"/>
        <one-to-many class="Test1.UDirectory,Test1"/>
      </set>
    </class>


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