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: 'NHibernate.Collection.Set' to type 'System.Collections.Set'
PostPosted: Mon Aug 28, 2006 7:49 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
NHibernate version: NHIBERNATE v1.0.2
Environment Used : ASP.NET ( C#) v2.0 - 2005
Name and version of the database i'm using: jojodb (sql serverexpress)

Dear Members,

My .cs file is:
namespace nhRegistration

{

public class Department

{

private int _id;

private string _name;

private IDictionary _classes;

private IDictionary _professors;

public Department()

{

// TODO: Add Constructor logic here :p

}

public int id

{

get

{

return _id;

}

set

{

_id = value;

}

}

public string name

{

get

{

return _name;

}

set

{

_name = value;

}

}

public IDictionary classes

{

get

{

return _classes;

}

set

{

_classes = value;

}

}

public IDictionary professors

{

get

{

return _professors;

}

set

{

_professors = value;

}

}

}

}



The mapping file coding is :

<?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" unsaved-value="0">

<generator class="assigned" />

</id>


<property name="name" column="deptname" type="String(50)"/>


<set name="classes" cascade="all">

<key column="deptid"></key>

<one-to-many class="nhRegistration.UniversityClass,nhRegistration"/>

</set>

<set name="professors" table="departmentprofessor">

<key column="deptid"></key>

<many-to-many class="nhRegistration.Person, nhRegistration"

column="PersonID" />

</set>

</class>

</hibernate-mapping>

In the database, i have the Department database filled with 2 records ...

The universityclass table is empty (no records submitted yet)

The DepartmentProfessor table is empty too (no records submitted yet)

Unable to cast object of type 'NHibernate.Collection.Set' to type 'System.Collections.IDictionary'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'NHibernate.Collection.Set' to type 'System.Collections.IDictionary'.

Source Error:

Line 55: ISession session = factory.OpenSession();
Line 56: ITransaction tx = session.BeginTransaction();
Line 57: IList depts = session.CreateCriteria(typeof(Department)).List();
Line 58: session.Close();
Line 59: return depts;


Source File: c:\Documents and Settings\bacem\My Documents\Jawad Files\JAWAD'S Project\JustinGehtland\App_Code\RegMgr.cs Line: 57

Stack Trace:

[InvalidCastException: Unable to cast object of type 'NHibernate.Collection.Set' to type 'System.Collections.IDictionary'.]
NHibernate.Persister.GetSetHelper_nhRegistration_Department.SetPropertyValues(Object obj, Object[] values) +170

[MappingException: Invalid mapping information specified for type nhRegistration.Department, check your mapping file for property type mismatches]
NHibernate.Persister.GetSetHelper_nhRegistration_Department.SetPropertyValues(Object obj, Object[] values) +320
NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values) +133
NHibernate.Impl.SessionImpl.InitializeEntity(Object obj) +499
NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session) +186
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +681
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +89
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +45
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) +344
NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session) +857
NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) +489
NHibernate.Impl.CriteriaImpl.List() +33
RegMgr.getDepartments() in c:\Documents and Settings\bacem\My Documents\Jawad Files\JAWAD'S Project\JustinGehtland\App_Code\RegMgr.cs:57

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +296
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +676
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2664
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +84
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +154
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.WebControls.DetailsView.DataBind() +24
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +91
System.Web.UI.WebControls.DetailsView.EnsureDataBound() +198
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +101
System.Web.UI.Control.EnsureChildControls() +134
System.Web.UI.Control.PreRenderRecursiveInternal() +109
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4435



public class RegMgr: IDBMgr
{
NHibernate.Cfg.Configuration config;
ISessionFactory factory;

public RegMgr()
{
config = new NHibernate.Cfg.Configuration();
config.AddClass(typeof(nhRegistration.Department));
config.AddClass(typeof(nhRegistration.Person));
config.AddClass(typeof(nhRegistration.UniversityClass));

factory = config.BuildSessionFactory();
}

public IList getDepartments()
{
ISession session = factory.OpenSession();
ITransaction tx = session.BeginTransaction();
[b] IList depts = session.CreateCriteria(typeof(Department)).List();[/b]
session.Close();
return depts;
}


Regards,
Jojorico

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 28, 2006 8:00 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
If the mappinf declares <set />, the property type must be IEsi.Collections.ISet

To use proeprty of type IDictionary, use <map> mapping

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 28, 2006 8:15 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
First of all thanks a lot for the reply.
<u>While changing the <set /> element to <map /> element, i've recieved the following Error message :</u>

<i>The element 'map' in namespace 'urn:nhibernate-mapping-2.0' has invalid child element 'one-to-many' in namespace 'urn:nhibernate-mapping-2.0'. List of possible elements expected: 'urn:nhibernate-mapping-2.0:index urn:nhibernate-mapping-2.0:composite-index urn:nhibernate-mapping-2.0:index-many-to-many urn:nhibernate-mapping-2.0:index-many-to-any'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.Schema.XmlSchemaValidationException: The element 'map' in namespace 'urn:nhibernate-mapping-2.0' has invalid child element 'one-to-many' in namespace 'urn:nhibernate-mapping-2.0'. List of possible elements expected: 'urn:nhibernate-mapping-2.0:index urn:nhibernate-mapping-2.0:composite-index urn:nhibernate-mapping-2.0:index-many-to-many urn:nhibernate-mapping-2.0:index-many-to-any'.

Source Error:


Line 22: {
Line 23: config = new NHibernate.Cfg.Configuration();
Line 24: config.AddClass(typeof(nhRegistration.Department));
Line 25: config.AddClass(typeof(nhRegistration.Person));
Line 26: config.AddClass(typeof(nhRegistration.UniversityClass));


Source File: c:\Documents and Settings\bacem\My Documents\Jawad Files\JAWAD'S Project\JustinGehtland\App_Code\RegMgr.cs Line: 24

Stack Trace:


[XmlSchemaValidationException: The element 'map' in namespace 'urn:nhibernate-mapping-2.0' has invalid child element 'one-to-many' in namespace 'urn:nhibernate-mapping-2.0'. List of possible elements expected: 'urn:nhibernate-mapping-2.0:index urn:nhibernate-mapping-2.0:composite-index urn:nhibernate-mapping-2.0:index-many-to-many urn:nhibernate-mapping-2.0:index-many-to-any'.]
NHibernate.Cfg.Configuration.ValidationHandler(Object o, ValidationEventArgs args) +45
System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(ValidationEventHandler eventHandler, Object sender, XmlSchemaValidationException e, XmlSeverityType severity) +68
System.Xml.Schema.XmlSchemaValidator.ElementValidationError(XmlQualifiedName name, ValidationState context, ValidationEventHandler eventHandler, Object sender, String sourceUri, Int32 lineNo, Int32 linePos, Boolean getParticles) +1470
System.Xml.Schema.XsdValidator.ValidateChildElement() +339
System.Xml.Schema.XsdValidator.ValidateElement() +72
System.Xml.Schema.XsdValidator.Validate() +98
System.Xml.XmlValidatingReaderImpl.ProcessCoreReaderEvent() +166
System.Xml.XmlValidatingReaderImpl.Read() +68
System.Xml.XmlValidatingReader.Read() +28
System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) +1364
System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) +78
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +430
System.Xml.XmlDocument.Load(XmlReader reader) +159
NHibernate.Cfg.Configuration.LoadMappingDocument(XmlTextReader hbmReader) +218
NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader) +36
NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream) +101

[MappingException: The element 'map' in namespace 'urn:nhibernate-mapping-2.0' has invalid child element 'one-to-many' in namespace 'urn:nhibernate-mapping-2.0'. List of possible elements expected: 'urn:nhibernate-mapping-2.0:index urn:nhibernate-mapping-2.0:composite-index urn:nhibernate-mapping-2.0:index-many-to-many urn:nhibernate-mapping-2.0:index-many-to-any'.]
NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream) +209
NHibernate.Cfg.Configuration.AddClass(Type persistentClass) +250

[MappingException: Error reading resource: nhRegistration.Department.hbm.xml]
NHibernate.Cfg.Configuration.AddClass(Type persistentClass) +341
RegMgr..ctor() in c:\Documents and Settings\bacem\My Documents\Jawad Files\JAWAD'S Project\JustinGehtland\App_Code\RegMgr.cs:24

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +103
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +261
System.Activator.CreateInstance(Type type, Boolean nonPublic) +66
System.Activator.CreateInstance(Type type) +6
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +242
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2664
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +84
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +154
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.WebControls.DetailsView.DataBind() +24
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +91
System.Web.UI.WebControls.DetailsView.EnsureDataBound() +198
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +101
System.Web.UI.Control.EnsureChildControls() +134
System.Web.UI.Control.PreRenderRecursiveInternal() +109
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4435</i>

Regards,
JojoRico

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 28, 2006 9:29 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
You must declare what is used for dictionary key value, with the <index> element of mapping. See http://www.hibernate.org/hib_docs/nhibernate/html/collections.html

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Tue Aug 29, 2006 2:25 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Thanks GERT for your great support .

but i've fixed my problem by using the ISet instead of IDictionary

Regards,
Jojo

_________________
In Code We Trust


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.