Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate Tips: performance tuning  RSS feed

 
satya Priya Sundar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Janssen,

Fist my congratulations for your new book.

On the topic of Performance Tuning in general ,How important is it to tune ORM Layer and in particular Hibernate ?
I have been researching in the official documentation of Hibernate, but can not find concrete examples to improve performance.

Regards
Sathya
 
Tim Holloway
Saloon Keeper
Posts: 18636
70
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tune only if you see performance issues and then tune only the problem parts. Attempting to tune everything just for the sake of tuning, like optimizing for the sake of optimizing is an inefficient use of valuable time and will generally make the system more expensive to keep running.

ORM or not, usually the first thing I do is run an EXPLAIN on the DBMS to see what's being done and how. If I can tune the underlying SQL query, that's well worth it. For one thing, the DBA becomes my friend.

The other place to look, after the SQL has executed, is in server-local caching. If you have an external cache, such as ehcache, that's worth getting stats from. If you think it's doing a good job, then start tweaking Hibernate caching. I'm assuming that you've already tweaked Hibernate's query/update components as part of the general SQL tuning.
 
Thorben Janssen
Author & Course Creator
Ranch Hand
Posts: 92
5
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sathya,

the importance of performance tuning depends on the size and complexity of your project.
As Tim wrote, as long as you don't have any performance issues, you don't need to optimize anything. For most small to medium sized projects, you don't need to tune anything on Hibernate.

If you see that one of your queries is slow, you should first have a look at the database and run an EXPLAIN ANALYZE. Most slow queries are caused by a missing index or an inefficient query. You can easily fix that without any Hibernate tuning.

Regards,
Thorben
 
satya Priya Sundar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Got it , appreciate your reply.

Not so related to the previous question nevertheless i had this question to ask

is there a way to tell hibernate engine to cache the sizes of the lazy collection so it doesn't need to hit the database when we do users.size() ?

Thanks
Sathya
 
Liar, liar, pants on fire! refreshing plug:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!