I have search for this thread, or a similar one, and not found one. So...
I am new to nHibernate, and have been attempting to set up the QuickStart example with no luck. I keep getting this error:
An unhandled exception of type 'NHibernate.MappingException' occurred in nhibernate.dll
Additional information: The 'Type' attribute is not declared. An error occurred at , (7, 43).
I am running it in a simple console application. Here is the class:
using System;
using NHibernate;
using NHibernate.Cfg;
using DataObjects;
namespace NHibernateTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Configuration cfg = new Configuration();
cfg.AddAssembly( "DataObjects" );
//cfg.AddAssembly( typeof( DataObjects.User ).Assembly );
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "
[email protected]";
newUser.LastLogon = DateTime.Now;
// Tell NHibernate that this object should be saved
session.Save(newUser);
// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
}
}
}
Here is my persistent object:
using System;
using System.Reflection;
namespace DataObjects
{
public class User
{
private string id;
private string userName;
private string password;
private string emailAddress;
private DateTime lastLogon;
public User()
{
}
public string Id
{
get { return id; }
set { id = value; }
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
public DateTime LastLogon
{
get { return lastLogon; }
set { lastLogon = value; }
}
}
}
and here is my User.hbm.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DataObjects.User, DataObjects" table="users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40" />
<property name="Password" type="String" length="20" />
<property name="EmailAddress" type="String" length="40" />
<property name="LastLogon" type="DateTime" />
</class>
</hibernate-mapping>
any help would be greatly appreciated.