Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<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 :

C#
<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 :

C#
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:
C#
<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:
C#
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:
C#
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.
Posted
Updated 26-Aug-17 20:37pm
v2
Comments
elothen 4-Aug-18 15:50pm    
I assume you finally resolved this. I'm experiencing the same issue learning NHibernate. What was your solution? Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900