Nadav
Nadav

Reputation:

NHibernate and sqlite - Could not compile the mapping document

I'm trying to run an NHibernate over sqlite. i have two projects: 1. Orange.Database - holds the pocos and daos and everything else 2. Orange.GUI - holds the gui...

when the program reach to the reach the:

  Configuration config = new Configuration();
  config.AddAssembly("Orange.Database");
  sessionFactory = config.Configure().BuildSessionFactory();

an exception is thrown: "Could not compile the mapping document: Orange.Database.Pocos.City.hbm.xml " inner exception: "Could not find the dialect in the configuration"

city.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               namespace="Orange.Database.Pocos">


<class name="City" table="Cities">
<id name="Id">
  <column name="Id" sql-type="int" not-null="true"/>
  <generator class="identity"/>
</id>

<property name="Name">
  <column name="name" not-null="true"/>
</property>

<property name="IsTaxFree">
  <column name="is_tax_free" not-null="true"/>
</property>
</class>
</hibernate-mapping>

I tried writting the assembly, and then removed it..

the app.config file:

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

<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="connection.driver_class">NHibernate.Driver.SQLiteDriver</property>
  <property name="connection.connection_string">
    Data Source=C:\Users\Nadav\Documents\Visual Studio 2005\Projects\orange\DB\OrangeDB\OrangeDB.db;Version=3
  </property>
  <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
  <property name="query.substitutions">true=1;false=0</property>

</session-factory>
</hibernate-configuration>
</configuration>

I've tried different location of the db file.. i have tried to remove the configSections and some other ideas i found on the web...

I'm using vs 2005 NHibernate version is 2.0.1.4000

Any suggestions?

Upvotes: 0

Views: 9711

Answers (3)

saeed
saeed

Reputation: 21

Do this in your code:

Configuration config = new Configuration();
config.Configure();
config.AddAssembly("Orange.Database");
sessionFactory = config.BuildSessionFactory();

Upvotes: 2

urkurk
urkurk

Reputation: 11

I got the same "could not compile error" but I'm not using sqlite.

I got it because I was calling the configure method from the nhibernate configuration instance twice.

Upvotes: 0

Diego Mijelshon
Diego Mijelshon

Reputation: 52753

First, download the latest stable version of NHibernate, 2.1.2.

Second, try creating a configuration file named hibernate.cfg.xml, containing:

<?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="connection.driver_class">NHibernate.Driver.SQLiteDriver</property>
        <property name="connection.connection_string">
            Data Source=C:\Users\Nadav\Documents\Visual Studio 2005\Projects\orange\DB\OrangeDB\OrangeDB.db;Version=3
        </property>
        <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
        <property name="query.substitutions">true=1;false=0</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    </session-factory>
</hibernate-configuration>

Upvotes: 0

Related Questions