JPA延迟加载性能有多重要? [英] How significant are JPA lazy loading performance benefits?

查看:152
本文介绍了JPA延迟加载性能有多重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解这是具体应用的高度具体,但我只是想知道一般意见是什么,或者至少是一些个人经历​​。

I understand that this is highly specific to the concrete application, but I'm just wondering what's the general opinion, or at least some personal experiences on the issue.

我对视图中的开放会话模式感到厌恶,所以为了避免这种情况,我正在考虑简单地抓取所有小东西,并在服务层中使用查询来获取更大的东西。

I have an aversion towards the 'open session in view' pattern, so to avoid it, I'm thinking about simply fetching everything small eagerly, and using queries in the service layer to fetch larger stuff.

有没有人用过这个并后悔了?在视图层中是否有一些我不知道的延迟加载的优雅解决方案?

Has anyone used this and regretted it? And is there maybe some elegant solution to lazy loading in the view layer that I'm not aware of?

推荐答案

延迟加载是只有在你根本不打算使用有问题的数据时才有用(例如只显示客户列表,特此忽略嵌套的订单),或者如果不确定用户是否想查看有问题的数据(例如,在内存中有客户列表,订单列表请求取决于未来的操作)。

Lazy loading is only beneficial if you aren't going to use the data in question at all (e.g. showing only a list of customers, hereby ignoring the nested set of orders), or if it's not to be decided yet whether the user would like to view the data in question (e.g. having a list of customers in memory and the request for list of orders depends on future actions).

如果您确定显示所有数据一次,然后不需要延迟加载,只需要额外的查询。

If you'll for sure show all the data at once, then lazy loading is not needed, it would only cost an extra query.

这篇关于JPA延迟加载性能有多重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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