Hello Everyone!!
I have been doing nhibernate since many days. But Today I stuck at a frustrating issue i.e. mapping exception.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="IPC.Base.Domains" assembly="IPC">
<class name="MenuItem" table="dbo.COR_MenuItem" default-access="property" default-cascade="save-update" default-lazy="true">
<cache usage="read-only" region="completelyStatic"/>
<id name="Id" type="System.Int32">
<generator class="identity" />
</id>
<property name="Name" type="System.String" />
<property name="Order" column="DisplayOrder" />
<property name="Key" column="KeyChain" />
<property name="Route" />
<property name="ActionMethod" />
<property name="IsHotlink" />
<many-to-one name="ParentMenuItem" column="ParentMenuItemId" class="MenuItem" cascade="none"/>
<bag name="MenuItems" table="dbo.COR_MenuItem" cascade="none">
<cache usage="read-only" region="completelyStatic"/>
<key column="ParentMenuItemId" />
<one-to-many class="MenuItem" />
</bag>
</class>
</hibernate-mapping>
And I do have a mapping class as following:
using System;
using System.Collections.Generic;
namespace IPC.Base.Domain
{
public partial class MenuItem : PersistentObject
{
public MenuItem()
{
MenuItems = new List<MenuItem>();
}
public virtual string Name { get; set; }
public virtual int? Order { get; set; }
public virtual string Key { get; set; }
public virtual string Route { get; set; }
public virtual string ActionMethod { get; set; }
public virtual bool IsHotlink { get; set; }
public virtual IList<MenuItem> MenuItems { get; set; }
public virtual MenuItem ParentMenuItem { get; set; }
/// <summary>
/// only to be used from the menu builder app
/// </summary>
/// <param name="id"></param>
public virtual void SetId(int id)
{
Id = id;
}
}
}
I have the following nHibernate Config running with the application. But as per my experience there is absolutely no issue with the nHibernate Config.
<?xml version="1.0"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="IPC">
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">**************SQL CONNECTION****************/property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
<property name="cache.use_query_cache">true</property>
<property name="show_sql">true</property>
<mapping assembly="IPC"/>
</session-factory>
</hibernate-configuration>
I am using the following line for code for invoking nHibernate session object to system.
static ISessionFactory CurrentFactory
{
get
{
if (factory == null)
{
Configuration cfg = new Configuration();
if (cfgFile == null)
cfg = cfg.Configure();
else
cfg = cfg.Configure(cfgFile);
factory = cfg.BuildSessionFactory();
}
return factory;
}
}
public static ISession Create()
{
var session = CurrentFactory.OpenSession();
return session;
}
Now! When I call the following line of code I am getting:
public virtual T Get(int id)
{
return Session.Get<T>(id);
}
No persister for: IPC.Base.Domain.MenuItem
Exception Details: NHibernate.MappingException: No persister for: IPC.Base.Domain.MenuItem
I have already enabled by nHibernate log. Following are the basic details from log
00:54:40.011 [4] INFO NHibernate.Cfg.Environment - NHibernate 2.1.0.4000 (2.1.0.4000)
00:54:40.055 [4] INFO NHibernate.Cfg.Environment - Bytecode provider name : lcg
00:54:40.057 [4] INFO NHibernate.Cfg.Environment - Using reflection optimizer
00:54:40.682 [4] DEBUG NHibernate.Cfg.Configuration - dialect=NHibernate.Dialect.MsSql2005Dialect
00:54:40.683 [4] DEBUG NHibernate.Cfg.Configuration - connection.driver_class=NHibernate.Driver.SqlClientDriver
00:54:40.683 [4] DEBUG NHibernate.Cfg.Configuration - connection.connection_string=*********************SQL Connection*****************
00:54:40.683 [4] DEBUG NHibernate.Cfg.Configuration - proxyfactory.factory_class=NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
00:54:40.683 [4] DEBUG NHibernate.Cfg.Configuration - cache.provider_class=NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache
00:54:40.683 [4] DEBUG NHibernate.Cfg.Configuration - cache.use_query_cache=true
00:54:40.683 [4] DEBUG NHibernate.Cfg.Configuration - show_sql=true
00:54:40.684 [4] DEBUG NHibernate.Cfg.Configuration - IPC<-IPC
00:54:40.685 [4] INFO NHibernate.Cfg.Configuration - Searching for mapped documents in assembly: IPC
00:54:40.689 [4] WARN NHibernate.Cfg.Configuration - No mapped documents found in assembly: IPC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
00:54:40.691 [4] INFO NHibernate.Cfg.Configuration - Configured SessionFactory: IPC
00:54:40.691 [4] DEBUG NHibernate.Cfg.Configuration - properties: System.Collections.Generic.Dictionary`2[System.String,System.String]
00:54:45.716 [4] INFO NHibernate.Cfg.Configuration - checking mappings queue
00:54:45.716 [4] INFO NHibernate.Cfg.Configuration - processing one-to-many association mappings
00:54:45.717 [4] INFO NHibernate.Cfg.Configuration - processing one-to-one association property references
00:54:45.717 [4] INFO NHibernate.Cfg.Configuration - processing foreign key constraints
00:54:45.747 [4] INFO NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2005Dialect
I have read almost all the post with stack! :) and even doing google for the same. The final words I am getting there is an issue with my assembly naming! I sure that there is a issue with the steps which I have followed. But still searching for that trigger!!!
Thanks! In advance!!