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

丶灬走出姿态 提交于 2020-01-24 05:37:31

问题


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?


回答1:


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.




回答2:


ORM lets you stay inside OOP world, but this comes at the cost of performance, especially with many to many relations in our case. We were using Hibernate as default, doing performance optimization with jdbc where required.




回答3:


Hibernate will make the development and maintenance of your app easier, but it won't necessarily make DB access quicker.

If your native JDBC calls use inefficient SQL then you might see some performance improvement as HIbernate tends to generate good SQL.



来源:https://stackoverflow.com/questions/3731008/performance-difference-of-native-sqlusing-mysql-vs-using-hibernate-orm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!