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
|