Search code examples
javaperformancehibernatedatabase-performancecpu-cache

Hibernate performance in terms of reads and writes


How does hibernate works in terms of reads and writes:

  1. How hibernate works if the application does more writes to DB? In this case i understand that the cache has to be refreshed for every write, apart from this is the any performance overhead (in compared with JDBC)

  2. How hibernate works if the application just read data(very less write/update)? In this case as cache is not required to be refreshed can we expect the performance of hibernate to be as good(or better) as JDBC(if tuned properly).

Also, want to understand the best option to use(apart from ORM) in case2.


Solution

  • Adding an extra layer is always less performant. However, this extra layer sometimes will also reduce development time. So it all depends upon your usecase and performance requirements. If you use ORM then you can enable 2nd level caching for reads and queries and that is your application level performance. But sometimes the native DB caching is quite enough (this way each node in cluster can avoid caching).