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.  [ 2 posts ] 
Author Message
 Post subject: The dialect was not set. Set the property hibernate.dialect
PostPosted: Sat May 03, 2008 8:19 am 
Newbie

Joined: Thu May 01, 2008 8:01 am
Posts: 3
while running my nhibernate application iam getting the following error:
The dialect was not set. Set the property hibernate.dialect.
Server Error in '/NHibernateASPSample' Application.
--------------------------------------------------------------------------------

The dialect was not set. Set the property hibernate.dialect.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.

Source Error:


Line 25: Configuration config = new Configuration();
Line 26:
Line 27: config.AddAssembly("NHibernateASPSample.Domain");
Line 28: _sessionFactory = config.Configure().BuildSessionFactory();
Line 29:


Source File: e:\samplecodes\zip_25\NHibernateASPSample\App_Code\SessionHelper.cs Line: 27

Stack Trace:


[HibernateException: The dialect was not set. Set the property hibernate.dialect.]
NHibernate.Dialect.Dialect.GetDialect() +127
NHibernate.Dialect.Dialect.GetDialect(IDictionary props) +82
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +27

[MappingException: Could not compile the mapping document: NHibernateASPSample.Domain.DbUser.hbm.xml]
NHibernate.Cfg.Configuration.LogAndThrow(MappingException me) +38
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +150
NHibernate.Cfg.Configuration.ProcessMappingsQueue() +12
NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) +169
NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) +177
NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) +97
NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) +133
SessionHelper.get_SessionFactory() in e:\samplecodes\zip_25\NHibernateASPSample\App_Code\SessionHelper.cs:27
SessionHelper.OpenSession() in e:\samplecodes\zip_25\NHibernateASPSample\App_Code\SessionHelper.cs:41
NHibernateHttpModule.get_CurrentSession() in e:\samplecodes\zip_25\NHibernateASPSample\App_Code\NHibernateHttpModule.cs:81
_Default.Page_Load(Object sender, EventArgs e) in e:\samplecodes\zip_25\NHibernateASPSample\Default.aspx.cs:18
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +80
System.Web.UI.Control.LoadRecursive() +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3750



my code is as follows:

code in web.config file

<?xml version="1.0" encoding="utf-8"?>
<configuration >
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">user id=sa;password=sqlserver;database=test;data source=DATASERVER;</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="default_schema">Northwind.dbo</property>
HBM Mapping Files
<mapping resource="DbUser.hbm.xml" assembly="NHibernateASPSample.Domain"/>
</session-factory>
</hibernate-configuration>


<!-- Compatible with IIS 6 -->
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<httpModules>
<add name="NHibernateHttpModule" type="NHibernateHttpModule"/>

</httpModules>
</system.web>
<!-- Compatible with IIS 7 -->
<!--
<system.webServer>
<modules>
<add name="NHibernateSessionModule" type="BasicSample.Web.NHibernateSessionModule" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
-->
</configuration>



code in DbUser.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="NHibernateASPSample.Domain"
assembly="NHibernateASPSample.Domain" default-lazy="false">

<class name="DbUser" table="DbUser">

<id name="IdUser" column="IdUser" type="Int32">
<generator class="identity"/>
</id>

<property name="Login" column="Login" type="String"/>
<property name="Password" column="Password" type="String"/>
<property name="UserData" column="UserData" type="String"/>

</class>

</hibernate-mapping>

code in NHibernateHttpModule.cs:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NHibernate;

/// <summary>
/// NHibernateHttpModule
/// </summary>
public class NHibernateHttpModule : IHttpModule
{
public const string KEY = "_TheSession_";
private static ISession _session;

public NHibernateHttpModule()
{
}

#region IHttpModule Members

public void Dispose()
{
}

public void Init(HttpApplication context)
{
}

#endregion

#region Session handling

private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
context.Items[KEY] = SessionHelper.OpenSession();
}

private void context_EndRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;

ISession session = context.Items[KEY] as ISession;
if (session != null)
{
try
{
session.Flush();
session.Close();
}
catch {}
}
context.Items[KEY] = null;
}

public static ISession CurrentSession
{
get
{
if (HttpContext.Current == null)
{
if (_session != null)
return _session;

_session = SessionHelper.OpenSession();
return _session;
}
else
{
HttpContext currentContext = HttpContext.Current;
ISession session = currentContext.Items[KEY] as ISession;
if (session == null)
{
session = SessionHelper.OpenSession();
currentContext.Items[KEY] = session;
}
return session;
}
}
}

#endregion
}

code in SessionHelper.cs:

using System;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NHibernate;
using NHibernate.Cfg;


/// <summary>
/// Summary description for SessionHelper
/// </summary>
public class SessionHelper
{
private static ISessionFactory _sessionFactory = null;
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
Configuration config = new Configuration();

config.AddAssembly("NHibernateASPSample.Domain");
_sessionFactory = config.Configure().BuildSessionFactory();

if (_sessionFactory == null)
throw new InvalidOperationException("Could not build SessionFactory");
}
return _sessionFactory;
}

}

public static ISession OpenSession()
{
ISession session;
session = SessionFactory.OpenSession();
if (session == null)
throw new InvalidOperationException("Cannot open session");

return session;
}

}
code in Default.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NHibernate;
using System.Collections;
using NHibernateASPSample.Domain;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ISession session = NHibernateHttpModule.CurrentSession;


IQuery query = session.CreateQuery("FROM DbUser");
IList result = query.List();

GridView1.DataSource = result;
GridView1.DataBind();


}


protected void Button1_Click(object sender, EventArgs e)
{
ISession session = NHibernateHttpModule.CurrentSession;
ITransaction transaction = session.BeginTransaction();

DbUser user = new DbUser();

user.Login = "codegod";
user.Password = "secret";
user.UserData = "vfgfhggfhgh";

session.Save(user);
transaction.Commit();

}
}

plz help me anyone regarding this error.
Thanx


Top
 Profile  
 
 Post subject: are you using activerecord
PostPosted: Wed Sep 10, 2008 12:49 am 
Newbie

Joined: Wed Jun 04, 2008 6:42 am
Posts: 2
Location: pune, india
If you are using caste activerecord for mapping the schema then you you need to define it as

<?xml version="1.0" encoding="utf-8" ?>
<activerecord>



<config>

<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />

<add key="hibernate.dialect" value="NHibernate.Dialect.MySQL5Dialect" />

<add key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver" />

<add key="hibernate.connection.connection_string" value="Server=127.0.0.1;Database=onlineexam;User ID=root;Password=admin;CharSet=latin1" />



<add key="show_sql" value="true" />


<!--<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Server=127.0.0.1;Database=onlineexam;User ID=root;Password=admin;CharSet=latin1</property>
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>-->

</config>



</activerecord>




replace the dialect property with hibernate.dialet. If you are not using activerecord then make sure that you have added the provider related to the database that you are using, in your case system.data.sqlclient. Also use the nhibernate helper class for easy configuration.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.