-->
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.  [ 3 posts ] 
Author Message
 Post subject: Troubles with configuration
PostPosted: Mon Sep 22, 2008 10:43 am 
Newbie

Joined: Thu Feb 14, 2008 4:52 pm
Posts: 3
Hi, I have troubles with NHibernate configuration.

Code shown below results with exception
Code:
System.InvalidOperationException: Could not find the dialect in the configuration
at NHibernate.Dialect.Dialect.GetDialect(IDictionary`2 props)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at DataLayer.Tests.FixtureBase.Before_each_test() in FixtureBase.cs: line 35
at DataLayer.Tests.FixtureBase.SetupContext() in FixtureBase.cs: line 19

Code:
17: Configuration cfg = new Configuration();
18: cfg.AddAssembly("DataLayer");
19: ISessionFactory factory = cfg.BuildSessionFactory();
20: ISession session = factory.OpenSession();


When I specify Dialect via cfg.Properties.Add(...) NHibernate throws new exception
Code:
NHibernate.HibernateException: The connection.driver_class must be specified in the NHibernate configuration section.
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
at NHibernate.Connection.UserSuppliedConnectionProvider.Configure(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at DataLayer.Tests.FixtureBase.Before_each_test() in FixtureBase.cs: line 35
at DataLayer.Tests.FixtureBase.SetupContext() in FixtureBase.cs: line 19

Sources for this exception:
Code:
16: Configuration cfg = new Configuration();
17: cfg.AddAssembly("DataLayer");
18: cfg.Properties.Add(Environment.Dialect, "NHibernate.Dialect.SQLiteDialect");
19: ISessionFactory factory = cfg.BuildSessionFactory();
20: ISession session = factory.OpenSession();


Hibernate version: 2.0.0GA

hibernate.cfg.xml (Copy to output directory: Copy always):

Code:
<?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">NHibernate.Dialect.SQLiteDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
    <property name="connection.connection_string">Data Source=:memory:;Version=3;New=True;</property>
    <property name="connection.release_mode">on_close</property>

    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>


SQLite version: 1.0.58.0


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2008 11:12 am 
Newbie

Joined: Thu Feb 14, 2008 4:52 pm
Posts: 3
Such solution works fine:
Code:
Dictionary<string, string> properties = new Dictionary<string, string>();
properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
properties.Add("dialect", "NHibernate.Dialect.SQLiteDialect");
properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
properties.Add("connection.connection_string", "Data Source=:memory:;Version=3;New=True;");
properties.Add("connection.release_mode", "on_close");

Configuration cfg = new Configuration();
cfg.Properties = properties;
ISessionFactory factory = cfg.BuildSessionFactory();
Session = factory.OpenSession();


But I still don't understand why hibernate.cfg.xml didn't work properly (T_T)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2008 3:44 am 
Newbie

Joined: Thu Feb 14, 2008 4:52 pm
Posts: 3
Solution for this problem is App.conf with such content:
Code:
<?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="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
      <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
      <property name="connection.connection_string">Data Source=:memory:;Version=3;New=True;</property>
      <property name="connection.release_mode">on_close</property>

      <property name="show_sql">true</property>
    </session-factory>
  </hibernate-configuration>
</configuration>


This problem cased by Dialect class wich asks Environment class for current configured Dialect. Environment class uses App.conf/Web.conf for load configuration by itself.


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