将 Hibernate 过滤器属性应用于具有多对多关系的 Bag [英] Applying the Hibernate filter attribute to a Bag with a many-to-many relationship

查看:15
本文介绍了将 Hibernate 过滤器属性应用于具有多对多关系的 Bag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下 Hibernate 映射文件:

Consider the following Hibernate mapping file:

<hibernate-mapping ...>
<class name="ContentPackage" table="contentPackages">
    <id name="Id" column="id" type="int"><generator class="native" /></id>
    ...
    <bag name="Clips" table="contentAudVidLinks">
      <key column="fk_contentPackageId"></key>
      <many-to-many class="Clip" column="fk_AudVidId"></many-to-many>
      <filter name="effectiveDate" condition=":asOfDate BETWEEN startDate and endDate"  />
    </bag>
</class>
</hibernate-mapping>

当我运行以下命令时:

  _session.EnableFilter("effectiveDate").SetParameter("asOfDate", DateTime.Today);

  IList<ContentPackage> items = _session.CreateCriteria(typeof(ContentPackage))
                                     .Add(Restrictions.Eq("Id", id))
                                     .List<ContentPackage>();

生成的 SQL 在中间映射表 (contentAudVidLinks) 上具有 WHERE 子句,而不是剪辑"表,即使我已将过滤器属性添加到剪辑包中.

The resulting SQL has the WHERE clause on the intermediate mapping table (contentAudVidLinks), rather than the "Clips" table even though I have added the filter attribute to the Bag of Clips.

我做错了什么?

推荐答案

想通了.对于任何感兴趣的人,我的 <filter> 属性放在错误的位置:

Figured it out. For anyone interested, I had my <filter> attribute in the wrong place:

之前:

<bag name="Clips" table="ctv_bb_contentAudVidLinks">
  <key column="fk_contentPackageId"></key>
  <many-to-many class="Clip" column="fk_AudVidId"></many-to-many>
  <filter name="effectiveDate" condition=":asOfDate BETWEEN startDate and endDate" />
</bag>

之后:

<bag name="Clips" table="ctv_bb_contentAudVidLinks">
  <key column="fk_contentPackageId"></key>
  <many-to-many class="Clip" column="fk_AudVidId">
    <filter name="effectiveDate" condition=":asOfDate BETWEEN startDate and endDate" />
  </many-to-many>
</bag>

这篇关于将 Hibernate 过滤器属性应用于具有多对多关系的 Bag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆