-->
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: Unknown entity class Error on retrieving a single object
PostPosted: Fri May 11, 2007 12:54 pm 
Newbie

Joined: Fri May 05, 2006 11:33 am
Posts: 6
Location: London
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


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.