深层对象图Hibernate [英] Deep Object Graphs Hibernate

查看:93
本文介绍了深层对象图Hibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的领域模型是非常紧密耦合的,一些使用hibernate映射的类是6个深度集合。目前,我们不使用延迟加载,因为业务层会传递一些较高级别的类并检索其中一些较低级别的子级,届时会话将被关闭。检索如此大量的数据来填充这个对象图似乎很昂贵,我怀疑域模型是否正确 - 也许我们应该减少深度并增加DAO的数量。在我看来,这一定是一个普通的权衡,这种估算正确吗?

解决方案

是的,这是一个普通的交易-off。我试图尽可能限制一个实体的最大1:n关联数。手动查询关联实体(使用优化查询)并创建数据传输对象以重新建立关联到复杂对象图中更容易。


Our domain model is very tightly coupled and some classes that are mapped with hibernate are 6 collections deep. Currently we don't use lazy loading for these since the business layer passes some of the higher level classes around and retrieves some of their lower level children at which time the session will have been closed. Retrieving such a large amount of data to populate this object graph seems expensive and I have doubts as to whether the domain model is correct - perhaps we should decrease the depth and increase the number of DAOs. It seems to me this must be a common trade-off, is this reckoning correct?

解决方案

Yes, it is a common trade-off. I try to limit the maximum number of 1:n associations from an entity as much a possible. It's a lot easier to manually query the associated entities (making use of optimized queries) and creating a data transfer object to re-establish the associations into a complex object graph.

这篇关于深层对象图Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆