NHibernate AssertException:Interceptor.OnPrepareStatement(SqlString)返回null或空SqlString

时间:2010-12-22 18:13:38

标签: nhibernate nhibernate-mapping interceptor

我正在尝试将表从多对一映射切换为具有中间映射表的多对多映射。但是,当我切换它并试图用NHibernate对它进行查询时,它给了我这个错误:“Interceptor.OnPrepareStatement(SqlString)返回null或空SqlString。”

我的查询最初是一些更复杂的问题,但我将其切换为基本的全部提取,我仍然遇到问题:

Session.QueryOver<T>().Future();

这似乎是我的模型映射文件中的问题或我的数据库中的某些问题。

以下是我的模型映射:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GBI.Core" namespace="GBI.Core.Models">

<class name="Market" table="gbi_Market">
    <id name="Id" column="MarketId">
        <generator class="identity" />
    </id>
    <property name="Name" />
    <property name="Url" />
    <property name="Description" type="StringClob" />
    <property name="Rating" />
    <property name="RatingComment" />
    <property name="RatingCommentedOn" />
    <many-to-one name="RatingCommentedBy" column="RatingCommentedBy" lazy="proxy"></many-to-one>
    <property name="ImageFilename" />
    <property name="CreatedOn" />
    <property name="ModifiedOn" />
    <property name="IsDeleted" />

    <many-to-one name="CreatedBy" column="CreatedBy" lazy="proxy"></many-to-one>
    <many-to-one name="ModifiedBy" column="ModifiedBy" lazy="proxy"></many-to-one>

    <set name="Content" where="IsDeleted=0 and ParentContentId is NULL" order-by="Ordering asc, CreatedOn asc, Name asc" lazy="extra">
        <key column="MarketId" />
        <one-to-many class="MarketContent" />
    </set>

    <set name="FastFacts" where="IsDeleted=0" order-by="Ordering asc, CreatedOn asc, Name asc" lazy="extra">
        <key column="MarketId" />
        <one-to-many class="MarketFastFact" />
    </set>

    <set name="NewsItems" table="gbi_NewsItem_Market_Map" lazy="true">
        <key column="MarketId" />
        <many-to-many class="NewsItem" fetch="join" column="NewsItemId" where="IsDeleted=0"/>
    </set>

    <!--<set name="MarketUpdates" table="gbi_Market_MarketUpdate_Map" lazy="extra">
        <key column="MarketId" />
        <many-to-many class="MarketUpdate" fetch="join" column="MarketUpdateId" where="IsDeleted=0" order-by="CreatedOn desc" />
    </set>-->

    <set name="Documents" table="gbi_Market_Document_Map" lazy="true">
        <key column="MarketId" />
        <many-to-many class="Document" fetch="join" column="DocumentId" where="IsDeleted=0"/>
    </set>
</class>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GBI.Core" namespace="GBI.Core.Models">

<class name="MarketUpdate" table="gbi_MarketUpdate">
    <id name="Id" column="MarketUpdateId">
        <generator class="identity" />
    </id>
    <property name="Description" />
    <property name="CreatedOn" />
    <property name="ModifiedOn" />
    <property name="IsDeleted" />

    <!--<many-to-one name="Market" column="MarketId" lazy="proxy"></many-to-one>-->

    <set name="Comments" where="IsDeleted=0" order-by="CreatedOn desc" lazy="extra">
        <key column="MarketUpdateId" />
        <one-to-many class="MarketUpdateComment" />
    </set>

    <many-to-one name="CreatedBy" column="CreatedBy" lazy="proxy"></many-to-one>
    <many-to-one name="ModifiedBy" column="ModifiedBy" lazy="proxy"></many-to-one>
</class>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GBI.Core" namespace="GBI.Core.Models">

<class name="MarketUpdateMarketMap" table="gbi_Market_MarketUpdate_Map">
    <id name="Id" column="MarketUpdateMarketMapId">
        <generator class="identity" />
    </id>
    <property name="CreatedOn" />
    <property name="ModifiedOn" />
    <property name="IsDeleted" />

    <many-to-one name="CreatedBy" column="CreatedBy" lazy="proxy"></many-to-one>
    <many-to-one name="ModifiedBy" column="ModifiedBy" lazy="proxy"></many-to-one>

    <many-to-one name="MarketUpdate" column="MarketUpdateId" lazy="proxy"></many-to-one>
    <many-to-one name="Market" column="MarketId" lazy="proxy"></many-to-one>
</class>

正如我所提到的,MarketUpdate原本是与市场多对一的(MarketId专栏仍在那里,但我忽略了它。这可能是个问题吗?)。但是我已经在Market_MarketUpdate_Map表中添加了它,使其成为多对多。

我正在试图弄清楚这可能是什么。搜索时我找不到任何对此错误的引用。并没有提供太多细节。

使用:

NHibernate 2.2

.NET 4.0

SQL Server 2005

2 个答案:

答案 0 :(得分:16)

原来问题只是在Visual Studio中将xml映射文件设置为内​​容而不是嵌入式资源。改变这一点解决了我的所有问题。

答案 1 :(得分:1)

如果您使用Fluent而不是xml进行映射并遇到此问题,请尝试删除%root%\LocalCache\NHibernate中生成的xml文件。