I am trying to make a mapping for 2 new classes Company, Country
Where company has many users and country contains many companies, but each user exists in one company and each company exists in one country.
After i did the mapping i tried running the project but an error occurred
Quote:
An association from the table cuyahoga_user refers to an unmapped class: Company .
Quote:
NHibernate 1.0.4:
Quote:
Company
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Cuyahoga.Core.Domain.Company, Cuyahoga.Core" table="cuyahoga_company">
<cache usage="read-write" />
<id name="Id" column="companyid" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property name="CompanyName" column="company_name" type="String" length="100" />
<property name="Address1" column="address1" type="String" length="100" />
<property name="Address2" column="address2" type="String" length="100" />
<property name="Phone" column="phone" type="String" length="25" />
<property name="Fax" column="fax" type="String" length="25" />
<property name="City" column="city" type="String" length="100" />
<property name="Website" column="website" type="String" length="100" />
<property name="State" column="state" type="String" length="50" />
<property name="PostalCode" column="postalcode" type="String" length="20" />
<property name="Industry" column="industry" type="String" length="250" />
<property name="InsertTimestamp" column="inserttimestamp" type="DateTime" />
<property name="UpdateTimestamp" column="updatetimestamp" type="DateTime" />
<!--<bag name="Users" cascade="none" lazy="true">
<key column="companyId"/>
<one-to-many class="Cuyahoga.Core.Domain.User , Cuyahoga.Core" />
</bag>-->
<bag name="Users" cascade="all-delete-orphan" lazy="true" >
<key column="companyId" />
<one-to-many class="CuyahogaCore.Domain.User, Cuyahoga.Core" />
</bag>
<many-to-one name="CompanyCountry" class="Cuyahoga.Core.Domain.Country, Cuyahoga.Core" column="countryid" cascade="all"/>
</class>
</hibernate-mapping>
Quote:
Country
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Cuyahoga.Core.Domain.Country, Cuyahoga.Core" table="cm_country">
<cache usage="read-write" />
<id name="Id" column="Country_Id" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="Name" column="Country_Name" type="String" length="50" />
<property name="Code" column="Country_Code" type="String" length="50" />
<bag name="Companies" cascade="all" lazy="true">
<key column="countryid"/>
<one-to-many class="Cuyahoga.Core.Domain.Company, Cuyahoga.Core " />
</bag>
</class>
</hibernate-mapping>
Quote:
User
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Cuyahoga.Core.Domain.User, Cuyahoga.Core" table="cuyahoga_user"
proxy="Cuyahoga.Core.Domain.User, Cuyahoga.Core">
<cache usage="read-write" />
<id name="Id" column="userid" type="Int32" unsaved-value="-1">
<generator class="native">
<param name="sequence">cuyahoga_user_userid_seq</param>
</generator>
</id>
<timestamp name="UpdateTimestamp" column="updatetimestamp" />
<property name="UserName" column="username" type="String" length="50" />
<property name="Password" column="password" type="String" length="100" />
<property name="FirstName" column="firstname" type="String" length="100" not-null="false" />
<property name="LastName" column="lastname" type="String" length="100" not-null="false" />
<property name="Title" column="title" type="String" length="50" />
<property name="Email" column="email" type="String" length="100" />
<property name="Website" column="website" type="String" length="100" />
<property name="TimeZone" column="timezone" type="Int32" />
<property name="IsActive" column="isactive" type="Boolean" length="100" />
<property name="LastLogin" column="lastlogin" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="LastIp" column="lastip" type="String" length="40" />
<property name="InsertTimestamp" column="inserttimestamp" type="DateTime" />
<many-to-one name="UserCompany" class="Cuyahoga.Core.Domain.Company, Cuyahoga.Core" column="companyid" cascade="none"/>
<bag name="Roles" table="cuyahoga_userrole" cascade="none" lazy="true">
<cache usage="read-write" />
<key column="userid" />
<many-to-many class="Cuyahoga.Core.Domain.Role, Cuyahoga.Core" column="roleid" outer-join="true" />
</bag>
</class>
</hibernate-mapping>
Quote:
stack trace
Code:
[MappingException: An association from the table cuyahoga_user refers to an unmapped class: Company]
NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done) +526
NHibernate.Cfg.Configuration.SecondPassCompile() +906
NHibernate.Cfg.Configuration.BuildSessionFactory() +12
Castle.Facilities.NHibernateIntegration.NHibernateFacility.ConfigureFactories(IConfiguration config, ISessionFactoryResolver sessionFactoryResolver, Boolean firstFactory) +792
Castle.Facilities.NHibernateIntegration.NHibernateFacility.ConfigureFacility() +357
Castle.Facilities.NHibernateIntegration.NHibernateFacility.Init() +51
Castle.MicroKernel.Facilities.AbstractFacility.Init(IKernel kernel, IConfiguration facilityConfig) +47
Castle.MicroKernel.DefaultKernel.AddFacility(String key, IFacility facility) +202
Castle.Windsor.WindsorContainer.AddFacility(String key, IFacility facility) +38
Castle.Windsor.Installer.DefaultComponentInstaller.SetUpFacilities(IConfiguration[] configurations, IWindsorContainer container) +307
Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store) +46
Castle.Windsor.WindsorContainer.RunInstaller() +75
Castle.Windsor.WindsorContainer..ctor(IConfigurationInterpreter interpreter) +150
Cuyahoga.Web.Components.CuyahogaContainer..ctor() in E:\WEb Site\Web\Components\CuyahogaContainer.cs:17
Cuyahoga.Web.Global.Application_Start(Object sender, EventArgs e) in E:\WEb Site\Web\Global.asax.cs:41
Quote:
Ms Sql 2005 sp1
Quote:
SQL
Code:
CREATE TABLE [dbo].[cuyahoga_company](
[company_id] [int] IDENTITY(1,1) NOT NULL,
[company_name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[address1] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[address2] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[phone] [nvarchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[fax] [nvarchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[city] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[website] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[state] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[countryid] [int] NULL,
[postalcode] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[industry] [nvarchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[inserttimestamp] [datetime] NULL CONSTRAINT [DF_cuyahoga_company_inserttimestamp] DEFAULT (getdate()),
[updatetimestamp] [datetime] NULL CONSTRAINT [DF_cuyahoga_company_updatetimestamp] DEFAULT (getdate()),
CONSTRAINT [PK_cuyahoga_company] PRIMARY KEY CLUSTERED
(
[company_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
Code:
ALTER TABLE [dbo].[cuyahoga_company] WITH CHECK ADD CONSTRAINT [FK_cuyahoga_company_cm_country] FOREIGN KEY([countryid])
REFERENCES [dbo].[cm_country] ([Country_Id])
Code:
CREATE TABLE [dbo].[cm_country](
[Country_Id] [int] IDENTITY(1,1) NOT NULL,
[Country_Code] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Country_Name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
CONSTRAINT [PK_cm_country] PRIMARY KEY CLUSTERED
(
[Country_Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Code:
CREATE TABLE [dbo].[cuyahoga_user](
[userid] [int] IDENTITY(1,1) NOT NULL,
[username] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[password] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[firstname] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[lastname] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[title] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[email] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[website] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[timezone] [int] NOT NULL CONSTRAINT [DF__cuyahoga___timez__7E6CC920] DEFAULT ((0)),
[isactive] [bit] NULL,
[lastlogin] [datetime] NULL,
[lastip] [nvarchar](40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[inserttimestamp] [datetime] NOT NULL CONSTRAINT [DF__cuyahoga___inser__7F60ED59] DEFAULT (getdate()),
[updatetimestamp] [datetime] NOT NULL CONSTRAINT [DF__cuyahoga___updat__00551192] DEFAULT (getdate()),
[companyId] [int] NULL,
CONSTRAINT [PK_user] PRIMARY KEY CLUSTERED
(
[userid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
CONSTRAINT [UC_user_username] UNIQUE NONCLUSTERED
(
[username] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
Code:
ALTER TABLE [dbo].[cuyahoga_user] WITH CHECK ADD CONSTRAINT [FK_cuyahoga_user_cuyahoga_company] FOREIGN KEY([companyId])
REFERENCES [dbo].[cuyahoga_company] ([company_id]
Quote:
classes
Quote:
Company
Code:
public class Company
{
private int _id;
private string _companyName;
private string _add1;
private string _add2;
private string _phone;
private string _fax;
private string _website;
private string _city;
private string _state;
private Country _country;
private string _postalCode;
private string _industry;
private IList _users;
private DateTime _insertTimestamp;
private DateTime _updateTimestamp;
#region properties
/// <summary>
/// Property Id (int)
/// </summary>
public virtual int Id
{
get { return this._id; }
set { this._id = value; }
}
/// <summary>
/// Property CompanyName (string)
/// </summary>
public virtual string CompanyName
{
get { return this._companyName; }
set { this._companyName = value; }
}
/// <summary>
/// Property Add1 (string)
/// </summary>
public virtual string Address1
{
get { return this._add1; }
set { this._add1 = value; }
}
/// <summary>
/// Property Add2 (string)
/// </summary>
public virtual string Address2
{
get { return this._add2; }
set { this._add2 = value; }
}
/// <summary>
/// Property Phone (string)
/// </summary>
public virtual string Phone
{
get { return this._phone; }
set { this._phone = value; }
}
/// <summary>
/// Property Fax (string)
/// </summary>
public virtual string Fax
{
get { return this._fax; }
set { this._fax = value; }
}
/// <summary>
/// Property City (string)
/// </summary>
public virtual string City
{
get { return this._city; }
set { this._city = value; }
}
/// <summary>
/// Property Website (string)
/// </summary>
public virtual string Website
{
get { return this._website; }
set { this._website = value; }
}
/// <summary>
/// Property State (string)
/// </summary>
public virtual string State
{
get { return this._state; }
set { this._state = value; }
}
/// <summary>
/// Property Country (Country)
/// </summary>
public virtual Country CompanyCountry
{
get { return this._country; }
set { this._country = value; }
}
/// <summary>
/// Property PostalCode (string)
/// </summary>
public virtual string PostalCode
{
get { return this._postalCode; }
set { this._postalCode = value; }
}
/// <summary>
/// Property Industry (string)
/// </summary>
public virtual string Industry
{
get { return this._industry; }
set { this._industry = value; }
}
public virtual IList Users
{
get
{
return _users;
}
set
{
_users = value;
}
}
/// <summary>
/// Property InsertTimestamp (DateTime)
/// </summary>
public virtual DateTime InsertTimestamp
{
get { return this._insertTimestamp; }
set { this._insertTimestamp = value; }
}
/// <summary>
/// Property UpdateTimestamp (DateTime)
/// </summary>
public virtual DateTime UpdateTimestamp
{
get { return this._updateTimestamp; }
set { this._updateTimestamp = value; }
}
#endregion
/// <summary>
/// Default constructor.
/// </summary>
public Company()
{
this._id = -1;
// Default to now, otherwise NHibernate tries to insert a NULL.
this._insertTimestamp = DateTime.Now;
_users = new ArrayList();
this._country = new Country();
}
}
Quote:
Country
Code:
namespace Cuyahoga.Core.Domain
{
public class Country
{
private int _id;
private string _name;
private string _code;
private IList _companyies;
/// <summary>
/// Property Id (int)
/// </summary>
public virtual int Id
{
get { return this._id; }
set { this._id = value; }
}
/// <summary>
/// Property Name (string)
/// </summary>
public string Name
{
get { return this._name; }
set { this._name = value; }
}
/// <summary>
/// Property Code (string)
/// </summary>
public string Code
{
get { return this._code; }
set { this._code = value; }
}
/// <summary>
/// Property Companies (IList)
/// </summary>
public IList Companies
{
get { return this._companyies; }
set { this._companyies = value; }
}
/// <summary>
/// Default constructor.
/// </summary>
public Country()
{
this._id = -1;
}
}
Quote:
Users
Code:
namespace Cuyahoga.Core.Domain
{
/// <summary>
/// Summary description for User.
/// </summary>
public class User : IIdentity
{
private int _id;
private string _userName;
private string _password;
private string _firstName;
private string _lastName;
private string _email;
private string _website;
private int _timeZone;
private bool _isActive;
private string _title;
private NullableDateTime _lastLogin;
private string _lastIp;
private bool _isAuthenticated;
private Company _company;
private IList _roles;
private AccessLevel[] _permissions;
private DateTime _insertTimestamp;
private DateTime _updateTimestamp;
#region properties
/// <summary>
/// Property Id (int)
/// </summary>
public virtual int Id
{
get { return this._id; }
set { this._id = value; }
}
/// <summary>
/// Property UserName (string)
/// </summary>
public virtual string UserName
{
get { return this._userName; }
set { this._userName = value; }
}
/// <summary>
/// Property Password (string). Internally the MD5 hash of the password is used.
/// </summary>
public virtual string Password
{
get { return this._password; }
set { this._password = value; }
}
/// <summary>
/// Property FirstName (string)
/// </summary>
public virtual string FirstName
{
get { return this._firstName; }
set { this._firstName = value; }
}
/// <summary>
/// Property LastName (string)
/// </summary>
public virtual string LastName
{
get { return this._lastName; }
set { this._lastName = value; }
}
/// <summary>
/// Property Title (string)
/// </summary>
public virtual string Title
{
get { return this._title; }
set { this._title = value; }
}
/// <summary>
/// The full name of the user. This can be used for display purposes. If there is no firstname
/// and lastname, the username will be returned.
/// </summary>
public virtual string FullName
{
get
{
if (this._firstName != null && this._firstName != String.Empty
&& this._lastName != null && this._lastName != String.Empty)
{
return this._firstName + " " + this._lastName;
}
else
{
return this._userName;
}
}
}
/// <summary>
/// Property Email (string)
/// </summary>
public virtual string Email
{
get { return this._email; }
set { this._email = value; }
}
/// <summary>
/// Property Website (string)
/// </summary>
public virtual string Website
{
get { return this._website; }
set { this._website = value; }
}
/// <summary>
/// The timezone offset of the user in minutes.
/// </summary>
public virtual int TimeZone
{
get { return this._timeZone; }
set { this._timeZone = value; }
}
/// <summary>
/// Property IsActive (bool)
/// </summary>
public virtual bool IsActive
{
get { return this._isActive; }
set { this._isActive = value; }
}
/// <summary>
/// Property UserCompany (Company)
/// </summary>
public virtual Company UserCompany
{
get { return this._company; }
set { this._company = value; }
}
/// <summary>
/// Property LastLogin (DateTime)
/// </summary>
public virtual NullableDateTime LastLogin
{
get { return this._lastLogin; }
set { this._lastLogin = value; }
}
/// <summary>
/// Property LastIp (string)
/// </summary>
public virtual string LastIp
{
get { return this._lastIp; }
set { this._lastIp = value; }
}
/// <summary>
/// Property Roles (IList)
/// </summary>
public virtual IList Roles
{
get { return this._roles; }
set { this._roles = value; }
}
/// <summary>
/// IIdentity property <see cref="System.Security.Principal.IIdentity" />.
/// </summary>
public virtual bool IsAuthenticated
{
get { return this._isAuthenticated; }
set { this._isAuthenticated = value; }
}