NHibernate配置问题

时间:2009-08-08 23:30:30

标签: nhibernate

我觉得发布这个很蠢,但我看不出这里有什么问题。我希望看到热门的Nhibernate工作,比我在网站上,下载它,并遵循快速入门教程,但做了一些机会 - 我使用MySql,它不是产品,而是我的项目中的用户,但无论如何。 ..

当我运行模式生成测试时,我收到错误,这是错误信息:

TestCase 'Uniflu.Domain.Tests.GenerateSchema_Fixture.Can_generate_schema'  
failed: NHibernate.MappingException : Could not compile the mapping document:  
Uniflu.Domain.Mappings.Usuario.hbm.xml  
----> NHibernate.HibernateException : Could not instantiate dialect class     
NHibernate.Dialect.MySqlDialect  
----> System.TypeLoadException : Could not load type NHibernate.Dialect.MySqlDialect.
Possible cause: no assembly name specified.  
em NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)  
em NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)  
em NHibernate.Cfg.Configuration.ProcessMappingsQueue()  
em NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)  
em NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)  
em NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)  
E:\Projetos\Uniflu\Uniflu\Uniflu.Domain\Tests\GenerateSchema_Fixture.cs(17,0): em Uniflu.Domain.Tests.GenerateSchema_Fixture.Can_generate_schema()  
--HibernateException  
em NHibernate.Dialect.Dialect.InstantiateDialect(String dialectName)  
em NHibernate.Dialect.Dialect.GetDialect(IDictionary`2 props)  
em NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)  
--TypeLoadException  
em NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName name, Boolean throwOnError)  
em NHibernate.Util.ReflectHelper.ClassForName(String name)  
em NHibernate.Dialect.Dialect.InstantiateDialect(String dialectName)  

0 passed, 1 failed, 0 skipped, took 5,37 seconds (NUnit 2.5).  

我的hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8" ?>  
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">  
<session-factory name="Test">  
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>  
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>  
<property name="dialect">NHibernate.Dialect.MySqlDialect</property>  
<property name="connection.connection_string">Server=Athenas;Database=uniflu;Uid=alaor;Pwd=test;</property>  
<property name="show_sql">true</property>  
</session-factory>  
</hibernate-configuration>  

我的用户类:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  

namespace Uniflu.Domain  
{  
    public class Usuario  
    {  
        public virtual Guid Id { get; set; }  
        public virtual String Nome { get; set; }  
        public virtual String Email { get; set; }  
        public virtual String Senha { get; set; }  
        public virtual String Dica { get; set; }  
        public virtual DateTime DataCriado { get; set; }  
        public virtual DateTime UltimoAcesso { get; set; }  
        public virtual Boolean Ativo { get; set; }  
    }  
}  

我的Usuario.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>  
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"  
               assembly="Uniflu.Domain"  
               namespace="Uniflu.Domain">  
<class name="Usuario">  
<id name="Id">  
<generator class="guid" />  
</id>  
<property name="Nome" />  
<property name="Email" />  
<property name="Senha" />  
<property name="Dica" />  
<property name="DataCriado" />  
<property name="UltimoAcesso" />  
<property name="Ativo" />  
</class>  
</hibernate-mapping>  

我的解决方案名称是Uniflu,我的项目是Uniflu.Domain,它是一个类库项目,目录结构是这样的:

Uniflu
- &GT; Uniflu.Domain
- &GT; - &GT;属性
- &GT; - &GT;参考
- &GT; - &GT;映射
- &GT; - &GT; - &GT; Usuario.hbm.xml
- &GT; - &GT;测试
- &GT; - &GT; - &GT; GenerateSchema_Fixture
- &GT; - &GT; hibernate.hbm.xml
- &GT; - &GT; Usuario.cs

Guyz我看不出我做错了什么......我真的需要一些亮点!请!!

提前谢谢。

2 个答案:

答案 0 :(得分:7)

MySQLDialect中错误拼写了hibernate.cfg.xml(请注意案例)。

始终注意异常消息和堆栈跟踪。

答案 1 :(得分:0)

确保您的映射文件具有* .hbm.xml扩展名(看起来像它),并且每个映射文件的构建类型都设置为“Embedded Resource”