Hibernate - 列表中类的限制
我正在尝试拉回集合中具有特定类型项目的项目列表。
例如:
<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="type" type="character" />
<subclass name="Lion" discriminator-value="L">
<property name="teeth" />
</subclass>
</class>
使用限制,我如何获得饲养狮子作为宠物的主人名单?
我尝试了以下方法但无济于事:
criteria.createCriteria("cats").add(Restrictions.eq("class", Lion.class));
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="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));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前(尽管我不确定这是否是故意的),其工作方式是您必须将鉴别器值指定为限制值,而不是类本身,所以:
在您的示例中。
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:
in your example.