开发者

Hibernate - Restriction for class in a list

开发者 https://www.devze.com 2023-01-02 12:15 出处:网络
I\'m trying to pull back a list of items that have a specific type of item in a set. For example: <class name=\"Owner\" table=\"OWNER\">

I'm trying to pull back a list of items that have a specific type of item in a set.

For example:

<class name="Owner" table="OWNER">
<id name="id" column="OWNER_ID" />
<set name="cats" table="OWNER_CATS" lazy="false">
    <key column="OWNER_ID" />
    <many-to-many class="Cat" />
</set>

<class name="Cat" table="CAT" discriminator-value="C">
<id name="id" column="CAT_ID" />
<discriminator column=开发者_StackOverflow中文版"type" type="character" />

<subclass name="Lion" discriminator-value="L">
    <property name="teeth" />
</subclass>
</class>

Using restrictions how would I get a list of owners who have lions as pets?

I've tried something along the lines of the following to no avail:

criteria.createCriteria("cats").add(Restrictions.eq("class", Lion.class));


At the moment (though I'm not sure if this is intentional) the way this works is you have to specify the discriminator value as the restriction value, rather than the class itself, so:

criteria.createCriteria("cats").add(Restrictions.eq("class", "L"));

in your example.

0

精彩评论

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