Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate and JDBC performance? [closed]

Currently i am switching my java web application from JDBC to Hibernate, in my current implementation with JDBC i load up static data on initialization of the application into static variables so i don't have to directly access the database every time i need some static data, now switching to hibernate i am thinking of getting rid of these static variables as as far as i have researched hibernate keeps loaded data in a cache.

I am fairly new to hibernate so i am not sure if switching from my current method to hibernate will give any performance improvements. I am going to research further into hibernates caching and run some performance tests to see which method is better but would just like some opinions on what others think regarding performance on both these methods.

Thanks.

like image 358
JCS Avatar asked Jun 17 '13 14:06

JCS


1 Answers

JDBC will always give better performance as compared to Hibernate for most of the database vendors. You can check the comparison made as given in the link below. He concludes that Hibernate is fast when querying tables with less rows else JDBC is way better:
http://phpdao.com/hibernate_vs_jdbc/

Another good performance stats can be found in Hibernate forum discussion at https://forum.hibernate.org/viewtopic.php?f=1&t=931708

It states the following order of performance hit taken due to use of Hibernate (please note that this can be improved by tuning Hibernate to one's needs:

Objects: 8 - Hibernate: 10ms / Direct JDBC: 10ms = Ratio: 1.0 
Objects: 16 - Hibernate: 10ms / Direct JDBC: 0ms = Ratio: Infinity 
Objects: 64 - Hibernate: 20ms / Direct JDBC: 10ms = Ratio: 2.0 
Objects: 256 - Hibernate: 150ms / Direct JDBC: 30ms = Ratio: 5.0 
Objects: 512 - Hibernate: 210ms / Direct JDBC: 40ms = Ratio: 5.25 
Objects: 1024 - Hibernate: 410ms / Direct JDBC: 70ms = Ratio: 5.857143 
Objects: 2048 - Hibernate: 681ms / Direct JDBC: 180ms = Ratio: 3.7833333


The choice of Hibernate over JDBC and SQL queries is not because of the performance, but because of reasons mainly object persistence and database independence in terms of not writing database specific queries. You can read the following PDF guide to get a better view:

  • http://www.mindfiresolutions.com/mindfire/Java_Hibernate_JDBC.pdf
like image 115
AurA Avatar answered Sep 29 '22 15:09

AurA