-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Could not compile the mapping document:The dialect was not
PostPosted: Mon Jul 14, 2008 6:04 am 
Newbie

Joined: Mon Jul 14, 2008 5:48 am
Posts: 5
Hi there,

Can I please request someone to help me with Nhibernate problem. I am newbie but I have read lots of stuff related to my error and unfortunately I dont get any solution which is working. When I try to run the Quickstart sample - I am having Visual Studio 2005 + Nhibernate 1.2.0 and SQL Server 2000.

I am getting an error as mentioned below.

Detail Error Message
Could not compile the mapping document: NHibernate.Examples.QuickStart.User.hbm.
xml
NHibernate.HibernateException: The dialect was not set. Set the property hiberna
te.dialect.
at NHibernate.Dialect.Dialect.GetDialect()
at NHibernate.Dialect.Dialect.GetDialect(IDictionary props)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc, String
name)

My .NET CLASS (Same as mentioned in QuickStart Guide - File is saved as Class1.cs)

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

namespace NHibernate.Examples.QuickStart
{
public class User
{
private string id;
private string userName;
private string password;
private string emailAddress;
private DateTime lastLogon;

public User()
{
}

public virtual string Id
{
get { return id; }
set { id = value; }
}

public virtual string UserName
{
get { return userName; }
set { userName = value; }
}

public virtual string Password
{
get { return password; }
set { password = value; }
}

public virtual string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}

public virtual DateTime LastLogon
{
get { return lastLogon; }
set { lastLogon = value; }
}
}
}


SQL TABLE (Same as mentioned in QuickStart Guide)

use Auction (as Auction is my DATABASE NAME)
go

CREATE TABLE users (
LogonID nvarchar(20) NOT NULL default '0',
Name nvarchar(40) default NULL,
Password nvarchar(20) default NULL,
EmailAddress nvarchar(40) default NULL,
LastLogon datetime default NULL,
PRIMARY KEY (LogonID)
)
go


NHibernate mapping file - user.hbm.xml (Build Action property is Embedded Resource)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.Examples.QuickStart.User, NHibernate.Examples" table="[Auction].[dbo].[Users]">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>


Application Configuration File (App.Config is a name)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
/>
</configSections>
<!-- Add this element -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
<session-factory xmlns="urn:nhibernate-configuration-2.0">
<property xmlns="urn:nhibernate-configuration-2.0"
name="hibernate.dialect"> NHibernate.Dialect.MsSql2000Dialect</property>
<property xmlns="urn:nhibernate-configuration-2.0"
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property xmlns="urn:nhibernate-configuration-2.0"
name="connection.connection_string">
Server=ALEPPO;initial
catalog=Auction;User ID=sa;Password=password;Integrated Security=True
</property>
<mapping xmlns="urn:nhibernate-configuration-2.0"
assembly="NHibernate.Examples" />
</session-factory>
</hibernate-configuration>
</configuration>

I have added Console Application Project in the same Solution. The Assembly name is ConsoleApplication1.


using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Examples.QuickStart;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples.QuickStart");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "joe@cool.com";
newUser.LastLogon = DateTime.Now;

// Tell NHibernate that this object should be saved
session.Save(newUser);

// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.InnerException);
Console.ReadLine();
}
}
}
}


Please Please help me ASAP. Thanks in advance.

REgards,
Nirav[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 6:48 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Afaik, inside App.config and Web.config you have to use the NameValue style:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="nhibernate"     type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <nhibernate>
    <add
      key="hibernate.connection.provider"
      value="NHibernate.Connection.DriverConnectionProvider"
    />
    <add
      key="hibernate.dialect"
      value="NHibernate.Dialect.MsSql2000Dialect"
    />
    ...
  </nhibernate>
<!-- other app specific config follows -->
</configuration>

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Could not compil Mapping Document - Still Not Working
PostPosted: Mon Jul 14, 2008 7:05 am 
Newbie

Joined: Mon Jul 14, 2008 5:48 am
Posts: 5
Hi wolli ,

Thanks a lot for quick reply. But After changing and recompile also its not working. Giving me same Error. Can u please advise?

I have changed the file as you mentioned. Below is new app.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<!-- Add this element -->
<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=ALEPPO;initial catalog=Auction;User ID=sa;Password=Password;Integrated Security=SSPI"
/>
</nhibernate>
</configuration>

Just for your information I have tried number of version like Nhibernate 1.2.0, Nhibernate 2.0 and all with appropriate documentation guide to get this working but its not working.

Regards,
Nirav


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 7:23 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
hmmm .... check if your App.Config is "EmbeddedResource", if yes, change it to "Content" (I remember stumbling over that before). And (at least in the post) you have a duplicate entry for "hibernate.connection.provider", maybe that's causing a key violation in the map and prevents the remaining keys from being read.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Could not compil Mapping Document - Still Not Working
PostPosted: Mon Jul 14, 2008 7:40 am 
Newbie

Joined: Mon Jul 14, 2008 5:48 am
Posts: 5
No....Its still same error wolly. I really appreciate your efforts & time. I have removed the Duplicate entry into app.config file. Also I tried to change Content Build Action for App.Config but its giving me same error.

Thanks again. Can u pls advise?

Regards,
Nirav


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 7:43 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Do you have more than one project in your solution ? You have to put the App.config in ConsoleApplication1. If that's still not the proble, I'm bailing out ... no further ideas ...

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Could not Compile the Mapping Document --- Working
PostPosted: Mon Jul 14, 2008 8:02 am 
Newbie

Joined: Mon Jul 14, 2008 5:48 am
Posts: 5
Hi Wolly,

Thanks a lot - Its working I have put App.Config into my Consoleapplication1 Project. After that I got exception for Assembly not found I changed my user.hbm.xml to below

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.Examples.QuickStart.User, NHibernate.Examples.QuickStart" table="[Auction].[dbo].[Users]">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>

and Its working. You are star mate. I have rated your post.

Cheers,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.