Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate performance [closed]

I have question, maybe from someone it see as stupid. Is Hibernate fast? I use it in system which would have really large count of queries to database. And performance become alerted. And other question off the point of current context. What would better - many simple query (with single table) or a bit less query with several JOIN?

Tanks for advance Artem

like image 558
Tioma Avatar asked Mar 01 '11 14:03

Tioma


People also ask

Why is Hibernate so slow?

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.

What is the problem with Hibernate?

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.

Is Hibernate faster?

From our experience Hibernate can be very fast. However, there can be many pitfalls that are specific to ORM tools including: Incorrect lazy loading, where too much or too little data is selected. N+1 select problems, where iterating over collections is slow.

Is Hibernate slower than JDBC?

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.


1 Answers

From our experience Hibernate can be very fast. However, there can be many pitfalls that are specific to ORM tools including:

  • Incorrect lazy loading, where too much or too little data is selected
  • N+1 select problems, where iterating over collections is slow
  • Collections of List should be avoided and prefer Set so ordering information does not need to be included in the table
  • Batch actions where it's best to fall back to direct SQL

The Improving Performance page in the Hibernate docs is a good place to start to learn about these issues and other methods to improve performance.

like image 94
Uriah Carpenter Avatar answered Sep 28 '22 02:09

Uriah Carpenter