【发布时间】:2012-01-11 19:08:35
【问题描述】:
以以下实体为例:
Entity Child {
long id;
String name;
long parentKey;
}
Entity Parent {
long id;
String desc;
}
有没有办法使用 Hibernate Criteria 查询:
select * from Child c, Parent p
where c.parentKey = p.id and c.name = "whatever" and p.desc = "whatever"
我们主要关心的是如何跨两个仅相关的实体加入 Criteria 按长键。
假设我们不能将 Parent 的引用直接放在 Child 中。
【问题讨论】:
-
“没有直接在我们的孩子中引用父母”意味着它是从父母到孩子的单向关系
-
它们必须是多头吗?你能为孩子创建一个 Key 对象吗?
标签: hibernate hibernate-criteria