我们如何减少不必要的对象加载? [英] How can we reduce the unnecessary loading of objects?

查看:98
本文介绍了我们如何减少不必要的对象加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在hibernate以及简单的ORM策略中,我通常会加载对象的所有值。是否有任何方法可以避免这种情况。
由于这个我的应用程序运行缓慢..

解决方案

有几种方法可以实现这一点:




  • 启用缓存。虽然SQL不会改变,但Hibernate会比较数据库的结果并重用现有的对象。这不会大大提升,但实现和维护起来很简单。

  • 创建第二个映射(相同的表,不同的对象)只加载一个子集。
  • 将很少使用的数据移动到第二个表中。

  • 使用自定义原生SQL查询加载对象。在这里,你必须确保你知道已经装载了多少以及如何填补空白。

In hibernate as well as simple ORM strategy,i am normally loading all the values for the objects.Is there any way to avoid this. Due to this my app running slowly..

解决方案

There are several ways to achieve this:

  • Enable caching. While the SQL won't change, Hibernate will compare the results from the database and reuse existing objects. This doesn't give an enormous boost but it's simple to implement and maintain.

  • Create a second mapping (same tables, different object) to load just a subset of the values.

  • Move the rarely used data into a second table.

  • Load your objects with a custom native SQL query. Here, you must make sure that you know how much has been loaded and how to "fill the gaps".

这篇关于我们如何减少不必要的对象加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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