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

发布于 2024-10-08 23:37:08 字数 4830 浏览 0 评论 0原文

我正在尝试将表从多对一映射切换为带有中间映射表的多对多。但是,当我切换它并尝试使用 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 最初是与 Market 的多对一(MarketId 列仍然在那里,但我忽略了它。这可能是一个问题吗?)。但我在 Market_MarketUpdate_Map 表中添加了它,使其成为多对多。

我一直在兜圈子,试图弄清楚这可能是什么。我在搜索时找不到任何对此错误的引用。而且它没有提供太多细节。

使用:

NHibernate 2.2

.NET 4.0

SQL Server 2005

I am trying to switch a table from being a many-to-one mapping to being many-to-many with an intermediate mapping table. However, when I switched it over and tried to do a query on it with NHibernate, it's giving me this error: "Interceptor.OnPrepareStatement(SqlString) returned null or empty SqlString."

My query was originally something more complex, but I switched it to a basic fetch all and I'm still having the problem:

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

It would seem to either be a problem in my model mapping files or something in my database.

Here are my model mappings:

<?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>

As I mentioned, MarketUpdate was originally a many-to-one with Market (MarketId column is still in there, but I'm ignoring it. Could this be a problem?). But I've added in the Market_MarketUpdate_Map table to make it a many-to-many.

I'm running in circles trying to figure out what this could be. I couldn't find any reference to this error when searching. And it doesn't provide much detail.

Using:

NHibernate 2.2

.NET 4.0

SQL Server 2005

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

送舟行 2024-10-15 23:37:08

事实证明,问题只是 xml 映射文件被设置为内容而不是 Visual Studio 中的嵌入资源。改变它解决了我所有的问题。

Turns out the problem was just that the xml mapping file was set as content instead of embedded resource in visual studio. Changing that fixed all my problems.

一袭白衣梦中忆 2024-10-15 23:37:08

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

If you're using Fluent rather than xml for mappings and encounter this issue, try deleting the generated xml files in %root%\LocalCache\NHibernate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文