-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Inheritence with NHibernate.Mapping.Attribute
PostPosted: Fri Feb 01, 2008 1:46 pm 
Newbie

Joined: Sat Jul 01, 2006 3:37 pm
Posts: 7
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 examplehttp://forum.hibernate.org/viewtopic.php?t=983628&highlight=


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.