<pre lang="text">I am trying to use nHibernate with SQL Server 2012 in my project. I am getting above said error" No persister for CafePOS.CafeTableGroup".My app.config file :
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=cafePOSdb;Integrated Security=True;</property>
<property name="proxyfactory.factory_class">NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate</property>
<mapping assembly="CafePOS" />
</session-factory>
</hibernate-configuration><pre>
My SessionFactory.cs file :
namespace CafePOS
{
public sealed class SessionFactory
{
private static volatile ISessionFactory iSessionFactory;
private static object syncRoot = new Object();
public static ISession OpenSession
{
get
{
if (iSessionFactory == null)
{
lock (syncRoot)
{
if (iSessionFactory == null)
{
Configuration configuration = new Configuration();
iSessionFactory = configuration.BuildSessionFactory();
}
}
}
return iSessionFactory.OpenSession();
}
}
}
}
My cafe_table_group.hbm.xml file:
<pre><?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="CafePOS" namespace="CafePOS" xmlns="urn:nhibernate-mapping-2.2">
<class name="cafe_table_group" table="cafe_table_group" lazy="true" >
<id name="cafe_table_group_id" column="cafe_table_group_id">
<generator class="identity" />
</id>
<property name="cafe_table_group_name">
<column name="cafe_table_group_name" sql-type="nvarchar" not-null="false" />
</property>
<property name="remarks">
<column name="remarks" sql-type="varchar" not-null="false" />
</property>
<property name="is_active">
<column name="is_active" sql-type="bit" not-null="false" />
</property>
<property name="group_position">
<column name="group_position" sql-type="int" not-null="false" />
</property>
<property name="color">
<column name="color" sql-type="nvarchar" not-null="false" />
</property>
<bag name="cafe_table">
<key column="cafe_table_group_id" />
<one-to-many class="cafe_table" />
</bag>
</class>
</hibernate-mapping>
Now this is my function to save table group:
using (ISession session = SessionFactory.OpenSession)
{
using (ITransaction transaction = session.BeginTransaction())
{
try
{
session.Save(group);
transaction.Commit();
return "1";
}
catch (Exception ex)
{
transaction.Rollback();
throw new Exception("Failed to create cafe table group." + ex.Message);
}
}
}
My CafeTableGroup.cs:
namespace CafePOS {
public class CafeTableGroup {
public CafeTableGroup() { }
public decimal cafe_table_group_id { get; set; }
public string cafe_table_group_name { get; set; }
public string remarks { get; set; }
public bool? is_active { get; set; }
public int? group_position { get; set; }
public string color { get; set; }
}
}
What I have tried:
I tried changing build action to embedded resource for cafe_table_group.hbm.xml file.