Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
NHibernate 1.2.1.4000
Class files:
ObjectBase.cs
Item.cs
Receipt.cs
ReceiptItem.cs
User.cs
Mapping documents:
Receipt.hbm.xml
ReceiptItem.hbm.xml
Item.hbm.xml
User.hbm.xml
Code between sessionFactory.openSession() and session.close():
Code:
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = null;
ITransaction transaction = null;
try
{
session = factory.OpenSession();
transaction = session.BeginTransaction();
Receipt rcp = new Receipt();
rcp.Items.Add(new ReceiptItem(new Item("Apples"), 1, 5));
session.Save(rcp);
transaction.Commit();
}
catch
{
if (transaction != null)
transaction.Rollback();
throw;
}
finally
{
if (session != null)
session.Close();
}
Full stack trace of any exception that occurs:Code:
[HibernateException: The class has no identifier property: DebtTracker.Objects.Receipt]
NHibernate.Persister.Entity.AbstractEntityPersister.GetIdentifier(Object obj) +164
NHibernate.Id.Assigned.Generate(ISessionImplementor session, Object obj) +137
NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything) +427
NHibernate.Impl.SessionImpl.Save(Object obj) +282
DebtTracker.Form1.NHTest() in C:\Code\VS2005\Projects\DebtTracker\DebtTracker\Form1.cs:86
DebtTracker.Form1..ctor() in C:\Code\VS2005\Projects\DebtTracker\DebtTracker\Form1.cs:30
[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) +268
System.Activator.CreateInstance(Type type, Boolean nonPublic) +66
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1036
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +114
System.Activator.CreateInstance(Type type, Object[] args) +16
96AAA.41AAA(String 0AAAA, String 1AAAA, Object[] 2AAAA) +127
96AAA.CreateMainForm() +243
86AAA.GetMainForm() +366
86AAA.ProcessRequest(HttpContext objHttpContext) +820
[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
86AAA.ProcessRequest(HttpContext objHttpContext) +4821
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Name and version of the database you are using:
Microsoft SQL Server (SQLEXPRESS)
The generated SQL (show_sql=true):
?
Debug level Hibernate log excerpt:
?
Problem:
I am trying to "NHibernate" my hierarchial class structure (specified above). HBMA seems to generate the mapping okay, as far as I understand, but when parsing it against the object I save in my runtime code, it doesn't find the object identifier in "Receipt".
My question is: Is the mapping correct for my class structure?
If yes: Why do I get that error message, and how do I solve it?
If no: How shall I configure my classes to get the correct mapping?
Note:
Start by looking att Receipt.cs and ObjectBase.cs. All my classes inherit ObjectBase, which contain the identifier I want to use in all my other classes.
Thanks in advance.