I am completely new to NHibernate. I saw many questions with the same title but I am unable to find the exact error. I am using NHibernate with SQL Server 2012.
My hibernate.cfg.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<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="show_sql">true</property>
<mapping assembly="CafePOS" />
</session-factory>
</hibernate-configuration>
My mapping model:
using System;
using System.Text;
using System.Collections.Generic;
namespace CafePOS
{
public class CafeTableGroup
{
//properties here
}
}
My hbm.xml
file:
<?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" >
<!--properties here -->
</class>
</hibernate-mapping>
My SessionFactory class:
namespace XXXXXX
{
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();
Assembly assembly = Assembly.GetCallingAssembly();
configuration.AddAssembly(assembly);
iSessionFactory = configuration.BuildSessionFactory();
}
}
}
return iSessionFactory.OpenSession();
}
}
}
}
This is the function that I tried to implement:
public static string Add(CafeTableGroup group)
{
using (ISession session = SessionFactory.OpenSession)
{
using (ITransaction transaction = session.BeginTransaction())
{
try
{
session.Save(group);
transaction.Commit();
return "1";
}
catch (Exception ex)
{
transaction.Rollback();
session.Close();
throw ex.InnerException;
}
}
}
}
I get error on the line
configuration.AddAssembly(assembly);
showing the error in the title:
Could not compile the mapping document: NHibernate
Inner exception message:
Could not find the dialect in the configuration
Thanks in advance.