HIbernate - @在XML配置中用于限制集合的等价物 [英] HIbernate - @Where equivalent in XML configuration for Restricting Collections

查看:105
本文介绍了HIbernate - @在XML配置中用于限制集合的等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用@Where提供的功能将收藏集限制为只有状态为ACTIVE的项目。
但是,我不能仅使用注释xml。因此,我在xml中查找了@Where,但我找不到任何东西。

I would like to use the functionality that is provided by @Where to restrict collections only to the items that have status ACTIVE. However, I cannot use annotations only xml. Therefore I look for @Where equivalent in xml but I cannot found anything.

示例(我需要类似元素where的元素)

Example ( I need something like element "where")

<hibernate-mapping>
<class name="Teacher" table="teacher" >
    ...

    <bag name="subjects" inverse="true" cascade="save-update">
        <key>
            <column name="id_policy" />
        </key>
        <one-to-many class="Subject" />
        <where>status = 'a'</where>
    </bag>

    ....
</class>
</hibernate-mapping>

当然,我可以使用自定义集合加载器,但对于这样简单的任务来说这非常难看。
过滤器是一个更合适的选项,但它必须为Hibernate会话明确启用,并且我只需要总是应用此where子句。

Of course, I can use the custom collection loader, but this is quite ugly for such simple task. The filter is a more suitable option but it must be enabled explicitly for Hibernate session and I simply need this "where" clause to be applied always.

任何想法?

推荐答案

The hibernate mapping DTD 在类元素和所有集合元素(set,bag等)上提及了一个可选的其中属性。 。它没有记录在DTD中,但给出了这里关于这个where属性,我很确定这是你在找什么。

The hibernate mapping DTD mentions an optional where attribute on the class element and on all the collection elements (set, bag, etc.). It's not documented in the DTD, but given what is written here regarding this "where" attribute, I'm pretty sure it's what you're looking for.

这篇关于HIbernate - @在XML配置中用于限制集合的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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