【发布时间】:2014-05-15 13:16:11
【问题描述】:
我有 2 张桌子:
- 主控
table具有某些对象的单一属性(id, name, title, ...) - 具有重复属性的表
(master_id, attribute_name, attribute_value)
#2 的示例数据:
- 10, "authors", "John Bill"
- 10, "authors", "Merry J"
- 10, "owners", "Chris O."
- 11, "authors", "Andrew K."
这是一个一对多的关系:
<set name="repeating" table="xxx" cascade="none" mutable="false" lazy="true" fetch="join">
<key column="...."/>
<one-to-many class="...." />
</set>
我想找到主对象(id=10),其中"authors" = "John Bill" 和"authors" = "Merry J" 和"owners" = "Chris O."
对于第一个条件,我可以这样做:
session.createCriteria(Master.class)
.createCriteria("repeating")
.add(Restrictions.eq("attributeName", "authors"))
.add(Restrictions.eq("attributeValue", "John Bill"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
如何使用 Criteria 添加其他条件?
谢谢
【问题讨论】:
标签: hibernate one-to-many criteria hibernate-criteria restrictions