简体   繁体   English

如何提高Java中的Hibernate性能?

[英]How to improve Hibernate performance in Java?

I have thousands of records which need to be retrieved on a single user click. 我有数千条记录需要在单个用户点击时检索。 Currently it is giving me the results very slowly, I have to wait for a long time. 目前它给我的结果很慢,我要等很长时间。 Is there a way to improve retrieving these results using hibernate? 有没有办法改善使用hibernate检索这些结果?

I have a case where a method which has a select query will run every single minute. 我有一种情况,其中具有选择查询的方法将每分钟运行一次。 This is where Hibernate is giving me the slow result. 这就是Hibernate给我缓慢结果的地方。 I am using Hibernate with MySQL. 我正在使用Hibernate和MySQL。

Common practice is enabling of 2nd level cache and query cache. 通常的做法是启用二级缓存和查询缓存。 Than your data will be readed from memmory not from db. 比你的数据将从memmory而不是db中获取。

Good article about it here 关于它的好文章在这里

Other things can be helpfull: 其他的东西可能会有所帮助:

1 Indexing - in case there is where and ordering - you have to build indexes for fields you are searching/ordering - this can improve search speed up 10 times 1索引 - 如果有位置和排序 - 你必须为你正在搜索/订购的字段构建索引 - 这可以提高搜索速度10倍

2 Denormalisation - if you have a lot of joins some denormalisation (putting all in single table) can help. 2非规范化 - 如果你有很多连接,那么一些非规范化(将所有这些都放在单个表中)可以提供帮助。 But this should be final solution when everything else fails. 但是当其他一切都失败时,这应该是最终解决方案

如果你必须在网页上显示记录并且一次检索100部分记录,我建议你去Pagination

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM