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?
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. I am using Hibernate with MySQL.
Depending on the number of selected Order entities, Hibernate might need to execute a huge number of queries that significantly slow down your application. This issue is easy to find. Hibernate's session statistics and Retrace provide you with the number of queries that were executed within a given session.
Both Hibernate & JDBC facilitate accessing relational tables with Java code. Hibernate is a more efficient & object-oriented approach for accessing a database. However, it is a bit slower performance-wise in comparison to JDBC.
This problem occurs when Hibernate performs 1 query to select n entities and then has to perform an additional query for each of them to initialize a lazily fetched association. Hibernate fetches lazy relationships transparently so that this kind of problem is hard to find in your code.
Common practice is enabling of 2nd level cache and query cache. Than your data will be readed from memmory not from 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
2 Denormalisation - if you have a lot of joins some denormalisation (putting all in single table) can help. But this should be final solution when everything else fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With