最近美国customer报了个问题,1条huge数据 (2个1000子数据)读取 java map out of memory.
分析了下原因,
A 表 onetomany B
A 表 onetomany C
A 表 onetoone D
读取A的一条数据 大约包含1000个B, 1000个C, 读取的时候就内存溢出了。
看了下log,发现读取的SQL: A left join B left join C leftjoin D,
返回 700,000条结果,这就是问题所在了。。。
这几个表每个表都 20+个column,再好的服务器也溢出了。
看了下A.hbm.xml, B 和 C 和 D都是 fetch=join.
fetch设置join, lazy只能是false。
分析下逻辑 1000个C 的访问性需求没1000个B高, 将C设置为fetch=select。
然后运行下,这次log里 原先sql 变为两个
A left join B leftjoin D,
select C,
发过去让customer 测试了下,好像可以了,这个问题暂时解决了。
one-to-many,fetch最好不要设置多个join,最常用的设为join。
如果设置个四五个,即使是一般不是很大的数据,结果数目 100x 100 X 100 X100还是很可怕的结果。
这样huge的数据,觉得还有问题,依次访问1000个B或C的关联对象 M或N时候 每访问一个会调用依次sql,
1000次的sql花费时间肯定不少。好在调用非PK属性时候才会调用SQL
分享到:
相关推荐
<one-to-one name="emp" class="Employees" fetch="join" constrained="true" cascade="save-update" > </one-to-one> </hibernate-mapping> Hibernate映射一对一(通过外键实现...
16.1.4. 返回多个实体(Returning multiple entities) 16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 ...
16.1.4. 返回多个实体(Returning multiple entities) 16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 ...
16.1.4. 返回多个实体(Returning multiple entities) 16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 ...
16.1.4. 返回多个实体(Returning multiple entities) 16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 ...
7.4.1. 一对多(one to many) / 多对一(many to one) 7.4.2. 一对一(one to one) 7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to ...
一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件(Component)映射 9.1. 依赖对象(Dependent objects) 9.2. 在集合中出现的依赖对象 ...
7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) 8.2. 在集合中出现的依赖对象 ...
8.5.1. 一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件(Component)映射 9.1. 依赖对象(Dependent objects) 9.2. 在集合中出现的依赖...
一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的关联映射 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) 8.2. 在...
16.1.4. 返回多个实体(Returning multiple entities) 16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 ...
16.1.4. 返回多个实体(Returning multiple entities) 16.1.4.1. 别名和属性引用(Alias and property references) 16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance...
8.5.1. 一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件(Component)映射 9.1. 依赖对象(Dependent objects) 9.2. 在集合中出现的依赖...
16.1.4. 返回多个实体(Returning multiple entities) 16.1.4.1. 别名和属性引用(Alias and property references) 16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance...
14.1.4. 返回多个实体(Returning multiple entities) 14.1.4.1. 别名和属性引用(Alias and property references) 14.1.5. 返回非受管实体(Returning non-managed entities) 14.1.6. 处理继承(Handling inheritance...
多对一(Many-to-One) 使用@ManyToOne批注来实现多对一关联。 @ManyToOne批注有一个名为targetEntity的参数,该参数定义了目标实体名,通常不需要定义该参数,因为在大部分情况下默认值(表示关联关系的属性类型)就...
14.1.4. 返回多个实体(Returning multiple entities) 14.1.4.1. 别名和属性引用(Alias and property references) 14.1.5. 返回非受管实体(Returning non-managed entities) 14.1.6. 处理继承(Handling inheritance...