Kishore Kishore - 20 days ago 9
Java Question

JDBC or Hibernate performance on a select query from a single table

I need to fetch records from a read only table based on user input. The number of requests from users to retrieve these records is approximately 50,000 - 60,000 per hour and table has millions of records.

I considered using plain JDBC but people suggested using Hibernate as it optimizes query for better performance. By using Hibernate over JDBC, am I going to get better performance?

I thought using an ORM solution is unnecessary here since it is just a single read only table. But if it is going to help with performance which is what I want, I would sure go for it. Any suggestions is greatly appreciated.

Answer

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/

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 PDF guide to get a better view.

http://www.mindfiresolutions.com/mindfire/Java_Hibernate_JDBC.pdf