Hi everyone
I'm trying to create a simple architecture for 2 objects.
User <--- WebUser. WebUser inherites from User.
But I'm not able to have the right mapping. Is there something I'm missing ?
Here's my 2 classes. Both fetch and save information in
the same table.
===========================================
User class
Code:
using System;
using NHibernate;
using NHibernate.Expression;
using NHibernate.Mapping.Attributes;
[Serializable]
[Class(Schema = "`dbo`", Table = "`[user]`")]
public class User
{
protected string userName;
protected string password;
protected int id;
public User()
{
}
//using the [id] and [generator] tag was not working
[RawXml(Content = @"
<id name=""ID"" column=""`user_id`"">
<generator class=""native"">
</generator>
</id>")]
public virtual int ID
{
get { return id; }
set { id = value; }
}
[Property(Column = "`user_name`")]
public virtual string UserName
{
get { return this.userName; }
set { this.userName = value; }
}
[Property(Column = "`password`")]
public virtual string Password
{
get { return this.password; }
set { this.password = value; }
}
}
Here's WebUser
Code:
using System;
using NHibernate;
using NHibernate.Expression;
using NHibernate.Mapping.Attributes;
[Serializable]
[Subclass(Name="WebUser",Extends="User")]
public class WebUser: User
{
protected string emailAddress;
public WebUser()
{
}
[Property(Column = "`email`")]
public virtual string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
}
Here's how I'm trying to call them.
Code:
//CREATE SESSSION FACTORY
configuration = new Configuration();
configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
configuration.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2000Dialect");
configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionString, System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString());
//configuration.AddInputStream(HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly()));
configuration.AddInputStream(HbmSerializer.Default.Serialize(typeof(User)));
configuration.AddInputStream(HbmSerializer.Default.Serialize(typeof(WebUser))); //<-- This is were it crashes
sessionFactory = configuration.BuildSessionFactory();
So each time the line
Code:
configuration.AddInputStream(HbmSerializer.Default.Serialize(typeof(WebUser))); //<-- This is were it crashes
is being executed, the application crashes and gives
me an mapping exception.
Does somebody knows what I'm missing or is there any good example on how using the inheritence with NHibernate.Mapping.Attribute
Thank you
Go See this link, somebody gave me a good example
http://forum.hibernate.org/viewtopic.php?t=983628&highlight=