Hibernate version: 1.2.0
Hi all,
I'm trying out NHibernate but i'm running into the above mentioned error when i'm trying to save an entity. Here's my code:
The class straight from the docs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1 {
public class Cat {
private string id;
private string name;
private char sex;
private float weight;
public Cat() {
}
public virtual string Id {
get { return id; }
set { id = value; }
}
public virtual string Name {
get { return name; }
set { name = value; }
}
public virtual char Sex {
get { return sex; }
set { sex = value; }
}
public virtual float Weight {
get { return weight; }
set { weight = value; }
}
}
}
The mapping file (named Cat.hbm.xml):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="ClassLibrary1.Cat, ClassLibrary1" table="Cat">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id">
<column name="CatId" not-null="true"/>
<generator class="assigned" />
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="Name">
<column name="Name" length="16" not-null="true" />
</property>
<property name="Sex" />
<property name="Weight" />
</class>
</hibernate-mapping>
My app.config:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="WindowsFormsApplication1">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</property>
<property name="connection.driver_class">NHibernate.JetDriver.JetDriver, NHibernate.JetDriver</property>
<property name="connection.connection_string">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb</property>
</session-factory>
</hibernate-configuration>
</configuration>
And finally the code to save the entity:
Code:
private void button1_Click(object sender, EventArgs e) {
Configuration config = new Configuration();
ISessionFactory sessionFactory = config.Configure().BuildSessionFactory();
config.AddAssembly("ClassLibrary1");
ISession session = sessionFactory.OpenSession();
ITransaction tx = session.BeginTransaction();
Cat princess = new Cat();
princess.Name = "Princess";
princess.Sex = 'F';
princess.Weight = 7.4f;
session.Save(princess);
tx.Commit();
session.Close();
sessionFactory.Close();
}
I'm getting the Unknown entity class on the session.Save(princess); line of code. When i debug the code and check the exception the inner exception is null. Here's the stacktrace:
Code:
bij NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(Type theClass)
bij NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass)
bij NHibernate.Impl.SessionImpl.GetEntityPersister(Object obj)
bij NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
bij NHibernate.Impl.SessionImpl.Save(Object obj)
bij WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in D:\Documenten\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:regel 36
bij System.Windows.Forms.Control.OnClick(EventArgs e)
bij System.Windows.Forms.Button.OnClick(EventArgs e)
bij System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bij System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bij System.Windows.Forms.Control.WndProc(Message& m)
bij System.Windows.Forms.ButtonBase.WndProc(Message& m)
bij System.Windows.Forms.Button.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.Run(Form mainForm)
bij WindowsFormsApplication1.Program.Main() in D:\Documenten\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:regel 15
bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()
So what am i doing wrong?