In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail the example analysis on the performance of Hibernate. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Hibernate does a very good job of solving performance problems. With its caching mechanism, using third-party caching and database connection pooling, the performance problem can be better solved. But that's not enough. Hibernate gives developers enough freedom to control performance issues.
After studying ibatis for a period of time, I think Hibernate has an advantage that ibatis can't replace.
1. Developers all know that Hibernate allows us to operate the database in the way of oo, which allows us to see the power of Hibernate and experience the convenience of manipulating data. But Gavin King says the most striking thing about Hibernate is Hibernate's caching mechanism, rather than operating the database in the way oo does. The caching mechanism of Hibernate is nothing more than first-level cache session, second-level cache sessionFactory, and third-party cache such as ehcache. That is, the big thing about Hibernate is its cache. Only by understanding this can we really understand Hibernate. Caching is so difficult that I haven't really understood it yet.
2, maintainability: ibatis promotes writing sql statements, which put sql statements into a separate xml file, this way has won the love of many developers, in a word, easy to maintain. But Hibernate also has this feature and is more powerful than ibatis. Hibernate named query / named parameter query, is to put hql statements in a separate xml file, it still allows people to manipulate data in an object-oriented way, which is loved by a large number of developers who follow the oo way, without having to write code in the oo way, and then change their mind to write those sql statements in a relationship-oriented way. But Hibernate doesn't just do that. Its native sql query completely satisfies the preference of sql statements. Like ibatis, it puts sql statements in the configuration file.
3. Hibernate performance: I firmly believe that Hibernate performance problems are not a problem. Considering that so many large and medium-sized projects are using Hibernate, do you still doubt the performance of Hibernate? After spring integrates Hibernate, you can use spring integrated jdbc or write stored procedures directly where there is a real performance bottleneck. But first of all, we have to confirm that this is really a performance bottleneck. I don't think we should take it for granted that the so-called performance problem has hindered a lot of people.
In my opinion, performance is nothing more than the number of sql statements sent. Good performance, send a few sql statements, poor performance, that is, send a large number of sql statements. Hibernate does a very good job of solving performance problems.
With its caching mechanism, using third-party caching and database connection pooling, the performance problem can be better solved.
But that's not enough. Hibernate gives developers enough freedom to control performance issues.
I think developers can tune themselves in the following areas:
Should ◆ always use jdbc placeholders in query strings? Or use named parameters: do not use string values instead of non-constant values in your query.
◆ Flush affects performance, and frequent refreshes affect performance to minimize unnecessary refreshes.
In the ◆ Cascade policy, set the cascade policy correctly in several-to-several relationships to figure out whether cascading Operand B is needed while operating on object A. For example, in the parent-son relationship of one to many, if the parent one is deleted and the child many needs to be cascaded, cascade = "delete" can be set on the one side. In this way, when the one is deleted, the child will be deleted automatically, but the operation on the child will not affect the parent. Cascade also has other property values that can improve performance as long as they are set correctly.
◆ lazy policy, correctly setting the deferred loading policy will also improve performance. In one to many or many to many, you should always delay loading the side of the many to memory. Set lazy= "true", first send sql statements to load yourself into memory, and only load cascading objects when needed; lazy= "false" will load both yourself and cascading objects into memory.
◆ also has the performance of the collection (set, list, map, array), which should be set correctly.
◆ uses third-party cache correctly. In the case of frequent read and write operations, using third-party cache can greatly improve performance. For example, the cache strategies of ehcache are: read-only,read-write and notstrict-read-write.
◆ with the release of the new version of Hibernate, and the development of technology, I believe that the performance of Hibernate will get better and better, all the performance is not the reason not to use Hibernate.
This is the end of this article on "sample Analysis of Hibernate performance". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.