PROBLEM SOLVED!
PROBLEM WAS: THE HBM.XML FILES WERE NOT SET TO "EMBEDDED RESOURCE".
THANKS ALL!
I've discarded ActiveRecord and ActiveWriter (didn't need GUI and version of writer isn't keeping up with NHibernate's latest).
Now I'm using MyGeneration which seems to be up-to-date in generating both hbm.xml and cs files for each table in my DB.
The program is a simple one-page tester to get started. All I'm trying to do is get started. I want to create a Contact entity/object, set some properties, persist the object to the DB. Then I'm trying to read it back.
Here's the documentation for v2.0 that I believe I'm following to the letter:
http://nhforge.org/doc/nh/en/#quickstart-intro
Does anyone just have a working example for NH v.2.0.1GA (in C# / ASP.NET) they could share or point me to one?
Thanks for any assistance.
The error and details follow. The only "Reference" in my project beyond the regular "System" ones added when creating a VS2008 project is 'NHibernate". Do I need others?
Documentation for 2.0 doesn't say anything about using AddAssembly, AddClass, or AddFile. I believe I've followed it to the letter.
Also, I'm using the hibernate.cfg.xml because the documentation's details don't seem to work in web.config. For example...
The documentation for 2.0 has:
<configSections>
<section
name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
/>
</configSections>
I tried using this and got:
"Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: An error occurred creating the configuration section handler for hibernate-configuration: Could not load file or assembly 'NHibernate' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 2: <configuration>
Line 3: <configSections>
Line 4: <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
.
.
.
"
-------------------------------------
Hibernate version: 2.0.1GA
hibernate.cfg.xml:
------------------
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=.\MYDB;Initial Catalog=myTable;Integrated Security=True</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
</session-factory>
</hibernate-configuration>
Default.aspx.cs
---------------
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.Configure();
NHibernate.ISessionFactory sessionFactory = cfg.BuildSessionFactory();
NHibernate.ISession session = sessionFactory.OpenSession();
session.BeginTransaction();
Contact myContact = new Contact();
myContact.Datecreated = DateTime.Now;
myContact.Company = "ABC Company";
myContact.Notes = "test";
session.SaveOrUpdate(myContact);
int test = myContact.Id;
session.Transaction.Commit();
Error:
------
Unknown entity class: MyProject.Contact
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: MyProject.Contact
Source Error:
Line 88: myContact.Notes = "test";
Line 89:
Line 90: session.SaveOrUpdate(myContact);
Line 91: int test = myContact.Id;
Line 92: session.Transaction.Commit();
Source File: C:\inetpub\ASPNET\MyProject\Default.aspx.cs Line: 90
Stack Trace:
[MappingException: Unknown entity class: MyProject.Contact]
NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(Type theClass) +176
NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass) +86
NHibernate.Impl.SessionImpl.GetEntityPersister(Object obj) +62
NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed, ISessionImplementor session) +211
NHibernate.Event.Default.AbstractSaveEventListener.GetEntityState(Object entity, String entityName, EntityEntry entry, ISessionImplementor source) +425
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) +121
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) +398
NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event) +116
NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj) +68
MyProject._Default.Page_Load(Object sender, EventArgs e) in C:\inetpub\ASPNET\MyProject\Default.aspx.cs:90
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627