开发者

HIbernate - @Where equivalent in XML configuration for Restricting Collections

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 equiva开发者_运维问答lent in xml but I cannot found anything.

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>

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.

Any ideas?


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.


you can easily add the where clause in the tag, like this example:

<bag name="subjects" inverse="true" cascade="save-update" where="flag_visible='S'" >
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜