5

我有 3 个实体和它们的嵌套集合,如下所示:实体 A 包含 B 的集合,实体 B 包含 C 的集合。

而且我需要获取实体 A 的完整对象图列表。当我将获取策略设置为 B 集合和 C 集合的“子选择”时,实际上仅通过单个查询读取 B 集合。每个 B 类型的每个实体都通过单独的查询读取 C 的每个集合 - 就像获取策略在那里“选择”一样。

所以我期待以下内容:

从 A 中选择 ...
select ... from B where a_id in (select id from A)
select ... from C where b_id in (select id from B where a_id in (select id from A)

但实际上得到:

从 A 中选择 ...
select ... from B where a_id in (select id from A)
select ... from C where b_id = ?
select ... from C where b_id = ?
...
select ... from C where b_id = ?

嵌套子选择是否有任何限制?

4

1 回答 1

0

问题已确定 - 映射到数据库的实体具有 getHashCode() 的自定义实现,它根据包括集合在内的所有内部成员的值计算哈希码。当 Hibernate 为实体 B 调用 getHashCode() 时,集合 C 尚未读取,但它是获取哈希所必需的。因此,执行单独的查询以获取当前对象 B 的 C 集合...

于 2012-10-06T20:27:06.817 回答