Alaor
Alaor

Reputation: 2191

NHibernate config problem

I feel so stupid for posting this but I can't see what's wrong here. I wanted to see hot Nhibernate works, than I got in the site, downloaded it, and was following the quick start tutorial but doing some chances - I'm using MySql and it's not a Product but a User in my project, but whatever...

When I run the test for schema generation I get an error, here is the error info:

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).  

My 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>  

My user class:

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; }  
    }  
}  

My 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>  

My solution name is Uniflu, my project is Uniflu.Domain, it's a class library project, the directory structure is like this:

Uniflu
-> Uniflu.Domain
-> -> Properties
-> -> References
-> -> Mapping
-> -> -> Usuario.hbm.xml
-> -> Tests
-> -> -> GenerateSchema_Fixture
-> -> hibernate.hbm.xml
-> -> Usuario.cs

Guyz I can't see what I'm doing wrong... I really need some light!! Please!!

Thankz in advance.

Upvotes: 2

Views: 11504

Answers (2)

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99730

You misspelled MySQLDialect (note the case) in your hibernate.cfg.xml.

Always pay attention to the exception message and stack trace.

Upvotes: 7

Sergey
Sergey

Reputation:

Make sure your mapping file has *.hbm.xml extension (which it looks like it does) and the build type for each mapping file is set to "Embedded Resource"

Upvotes: 0

Related Questions