1

我遇到了用sqlite設置nHibernate的實際問題。nHibernate和sqlite映射

這裏是hibernate.cfg.xml文件:

<?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.SQLite20Dialect</property> 
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> 
    <property name="connection.connection_string">Data Source=books.db;Version=3</property> 
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 
    <property name="query.substitutions">true=1, false=0</property> 

    <property name="show_sql">true</property> 
    <property name="format_sql">true</property> 


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

,這裏是(簡化)的映射文件:

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly ="DataAccess" namespace="DataAccess.DOM"> 
    <class name="Book" table="book"> 
    <id name="id" type="integer" unsaved-value="null"> 
     <generator class="increment"/> 
    </id> 

    <property name="isbn" type="string" length="25"/> 
    <property name="author" type="string" length="100"/> 

    </class> 
</hibernate-mapping> 

表:

create table book(
    id INTEGER primary key, 
    author TEXT, 
    isbn TEXT, 
); 

我得到錯誤: 「無法編譯映射文檔:DataAccess.DOM.Book.hbm.xml」

我在Vista 32bit上開發VS2008。

我已經添加了System.Data.SQlite程序集並設置爲複製本地。

有什麼建議嗎?

回答

2

這個很久以前我固定的,現在不記得正是我所做的:O(

然而,看代碼:我注意到這種變化映射文件,我改變了標籤的標識從整數的Int32和發電機類從增量到本機:

<id name="Id" type="Int32" unsaved-value="0"> 
    <generator class="native"/> 
</id> 
1

您是否將hbm.xml文件嵌入到程序集中?

https://www.hibernate.org/362.html摘自:

注:如果您使用Visual Studio .NET編譯確保您設置的User.hbm.xml文件嵌入的資源的生成操作。映射文件現在將成爲Asssembly的一部分。細節的重要性稍後會顯而易見。

+0

我已經 – 2009-10-06 11:21:30

+0

仍然嵌在hbm.xml文件中的應用程序了與SqlServerCE工作作爲數據庫,但我嘗試切換到SQLite的。得到這個錯誤。 – 2009-10-06 11:22:09

0

在你的書中映射文件,這樣設置屬性:

<property name="isbn" column="isbn"/> 
<property name="author" column="author"/> 

另外,還要確保你在上面的名稱屬性的值,因爲他們是你的類相同的情況。