hi everyone,
So I haven't been able to use NHibernate for a while and in this time its gone from 1.0.2 to 1.2. Anyway, I'm creating a simple web site to store and maintain information (vs2005).
I've downloaded 1.2 and followed some of the quickstart examples for 1.2 and created the NHibernateFactory. Now, on the first page, i'm just using the standard "GetAllDepartments" method where i do :
public IList GetAllDepartments()
{
IList allDepartments;
ISession mySession = NHibernateHelper.GetCurrentSession();
ITransaction myTransaction = mySession.BeginTransaction();
allDepartments= mySession.Find("from SJBerwin.Apps.ServerInfo.App_Code.DataAccess.SiDepartment as SiDepartment");
myTransaction.Commit();
myTransaction = null;
mySession = null;
NHibernateHelper.CloseSession();
return allDepartments;
}
This works fine. I'm binding a GridView to an objectDataSource and binding this to the collection. I then add an "edit" button which will redirect to a separate page to modify the details. Here's the problem. I'm trying to retrieve a single record, and using the code below :
public SiDepartment GetDepartment(decimal DepartmentId)
{
SiDepartment myDepartment;
ISession mySession = NHibernateHelper.GetCurrentSession();
ITransaction myTransaction = mySession.BeginTransaction();
** ERROR HERE*** myDepartment = (SiDepartment)mySession.Load(typeof(SiDepartment), DepartmentId);
myTransaction.Commit();
myTransaction = null;
mySession = null;
NHibernateHelper.CloseSession();
return myDepartment;
}
When i run the line thagt gives the error (marked above), i get the error at the bottom. Now i've tried to use the load and pass in a new instance of SiDepartment, Ive even tried the Get. They all fail and give the same error.
The weird thing is the getAllDepartments works and also the SaveDepartment. Why does the single retrieve fail?
Thanks guys, help is definately appreciated!
Toast
Unknown entity class: SJBerwin.Apps.ServerInfo.App_Code.DataAccess.SiDepartment
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: NHibernate.MappingException: Unknown entity class: SJBerwin.Apps.ServerInfo.App_Code.DataAccess.SiDepartment
Source Error:
Line 62: ITransaction myTransaction = mySession.BeginTransaction();
Line 63: myDepartment = new SiDepartment();
Line 64: mySession.Load(myDepartment, departmentId);
Line 65: myTransaction.Commit();
Line 66: myTransaction = null;
Source File: c:\Documents and Settings\waat\My Documents\Visual Studio 2005\Projects\SJBerwin.Apps.ServerInfo\SJBerwin.Apps.ServerInfo\App_Code\Factory\DepartmentFactory.cs Line: 64
Stack Trace:
[MappingException: Unknown entity class: SJBerwin.Apps.ServerInfo.App_Code.DataAccess.SiDepartment]
NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(Type theClass) +164
NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass) +69
NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) +198
NHibernate.Impl.SessionImpl.DoLoadByObject(Object obj, Object id, LockMode lockMode) +188
NHibernate.Impl.SessionImpl.Load(Object obj, Object id) +140
SJBerwin.Apps.ServerInfo.Factory.DepartmentFactory.GetDepartment(Decimal departmentId) in c:\Documents and Settings\waat\My Documents\Visual Studio 2005\Projects\SJBerwin.Apps.ServerInfo\SJBerwin.Apps.ServerInfo\App_Code\Factory\DepartmentFactory.cs:64
|