Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance difference of Native SQL(using MySQL) vs using Hibernate ORM?

I am using Spring MVC for an application that involved a multilevel back end for management and a customer/member front end. The project was initially started with no framework and simple native JDBC calls for database access.

As the project has grown significantly(as they always do) I have made more significant database calls, sometimes querying large selection sizes.

I am doing what I can to treat my db calls to closely emulate Object Relational Mapping best practices, but am still just using JDBC. I have been contemplating on whether or not I should make the transition to hibernate, but was unsure if it would be worth it. I would be willing to do it, if it was worth a performance gain.

Is there any performance gain from using Hibernate( or even just Object Relational Mapping) over native SQL using JDBC?

like image 564
TheJediCowboy Avatar asked Dec 22 '22 23:12

TheJediCowboy


1 Answers

Is there any performance gain from using Hibernate (or even just Object Relational Mapping) over native SQL using JDBC?

Using an ORM, a datamapper, etc won't make the same SQL queries run faster. However, when using Hibernate you can benefit from things like lazy loading, second level caching, query caching and these features might help to improve the performances. I'm not saying Hibernate is perfect for every use case (for the special cases Hibernate can't handle well, you can always fall back to native SQL) but it does a very decent job and definitely improves development time (even after adding time spent on optimization).

But the best way to convince yourself would be to measure things and in your case, I would probably create an Hibernate prototype covering some representative scenarios and bench it.

like image 99
Pascal Thivent Avatar answered Jan 14 '23 01:01

Pascal Thivent