无法编译映射文件:NHibernate
Could not compile the mapping document: NHibernate
我对 NHibernate 完全陌生。我看到许多标题相同的问题,但我找不到确切的错误。我在 SQL Server 2012 中使用 NHibernate。
我的 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>
我的映射模型:
using System;
using System.Text;
using System.Collections.Generic;
namespace CafePOS
{
public class CafeTableGroup
{
//properties here
}
}
我的 hbm.xml
文件:
<?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>
我的 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();
}
}
}
}
这是我尝试实现的功能:
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;
}
}
}
}
我在线上出错
configuration.AddAssembly(assembly);
显示标题中的错误:
Could not compile the mapping document: NHibernate
内部异常消息:
Could not find the dialect in the configuration
提前致谢。
您应该在根文件夹中有文件 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="dialect">Netsis.Framework.Persister.Hibernate.Dialect.NMsSql2008Dialect, Netsis.Framework.Persister</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=localhost;Initial Catalog=CRM;Persist Security Info=True;User ID=user;Password=pass</property>
<property name="proxyfactory.factory_class">Netsis.Framework.Persister.Hibernate.Proxy.PropertyReaderProxyFactoryFactory,Netsis.Framework.Persister</property>
<property name="show_sql">True</property>
<property name="format_sql">True</property>
<property name="adonet.batch_size">30</property>
</session-factory>
</hibernate-configuration>
您的 class 名字不是 cafe_table_group
,而是 CafeTableGroup
。
你能试试把你的 hbm.xml
改成
<class name="CafeTableGroup" table="cafe_table_group" lazy="true">
**************
我对 NHibernate 完全陌生。我看到许多标题相同的问题,但我找不到确切的错误。我在 SQL Server 2012 中使用 NHibernate。
我的 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>
我的映射模型:
using System;
using System.Text;
using System.Collections.Generic;
namespace CafePOS
{
public class CafeTableGroup
{
//properties here
}
}
我的 hbm.xml
文件:
<?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>
我的 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();
}
}
}
}
这是我尝试实现的功能:
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;
}
}
}
}
我在线上出错
configuration.AddAssembly(assembly);
显示标题中的错误:
Could not compile the mapping document: NHibernate
内部异常消息:
Could not find the dialect in the configuration
提前致谢。
您应该在根文件夹中有文件 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="dialect">Netsis.Framework.Persister.Hibernate.Dialect.NMsSql2008Dialect, Netsis.Framework.Persister</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=localhost;Initial Catalog=CRM;Persist Security Info=True;User ID=user;Password=pass</property>
<property name="proxyfactory.factory_class">Netsis.Framework.Persister.Hibernate.Proxy.PropertyReaderProxyFactoryFactory,Netsis.Framework.Persister</property>
<property name="show_sql">True</property>
<property name="format_sql">True</property>
<property name="adonet.batch_size">30</property>
</session-factory>
</hibernate-configuration>
您的 class 名字不是 cafe_table_group
,而是 CafeTableGroup
。
你能试试把你的 hbm.xml
改成
<class name="CafeTableGroup" table="cafe_table_group" lazy="true">
**************