In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Development speed comparison
Hibernate is harder to master than Mybatis. Mybatis framework is relatively simple and easy to use, but also relatively rudimentary. Personally, I think that to use Mybatis well, we should first understand Hibernate well.
development community
Hibernate and Mybatis are popular persistence layer development frameworks, but Hibernate development community is relatively lively, support tools are also many, updates are also fast, the current maximum version 4.1.8. Mybatis is relatively quiet and has fewer tools, with the current maximum version 3.2.
development workload
Hibernate and MyBatis both have corresponding code generation tools. Simple basic DAO layer methods can be generated.
For advanced queries, Mybatis requires manual writing of SQL statements, as well as ResultMap. Hibernate has a good mapping mechanism, developers do not need to care about SQL generation and result mapping, can focus more on business processes.
2. System tuning versus Hibernate tuning
Formulate reasonable cache strategy;
Try to use delayed loading characteristics;
adopt reasonable Session management mechanism;
Use batch capture, set reasonable batch processing parameters (batch_size);
Reasonable O/R mapping design
Mybatis tuning scheme
MyBatis is consistent with Hibernate's Session lifecycle in terms of Session, and also requires a reasonable Session management mechanism. MyBatis also has a second-level cache mechanism. MyBatis allows for detailed SQL optimization design.
SQL optimization aspects
Hibernate queries will query all the fields in the table, which has a performance cost. Hibernate can also write its own SQL to specify the fields that need to be queried, but this destroys the simplicity of Hibernate development. Mybatis SQL is written manually, so you can specify the fields of the query on demand.
Hibernate HQL tuning requires SQL to be printed, and Hibernate SQL is rejected by many because it is too ugly. MyBatis SQL is written manually by myself, so it is easy to adjust. Hibernate has its own log statistics. Mybatis itself does not have logging statistics, using Log4j for logging.
extensibility aspect
Hibernate and specific database association can be configured in XML files, all HQL statements have nothing to do with the specific database used, portability is very good. All SQL statements in MyBatis project are dependent on the database used, so support for different database types is not good.
3. Object Management and Capture Strategy Object Management
Hibernate is a complete object/relational mapping solution that provides object-state management capabilities, freeing developers from the details of the underlying database system. In other words, Hibernate takes a more natural object-oriented view of persisting data in Java applications than the common JDBC/SQL persistence layer scenario requires managing SQL statements.
In other words, developers who use Hibernate should always focus on the state of the object, regardless of the execution of SQL statements. Hibernate is in charge of these details, which developers only need to know when tuning system performance.
MyBatis has no documentation in this area, and users need to manage the objects themselves in detail.
grasping strategy
Hibernate has a good mechanism for grabbing objects associated with entities. For each association relationship, you can set whether to delay loading in detail, and provide four modes: association grab, query grab, sub-query grab, and batch grab. It is configured and handled in detail.
Mybatis's delayed loading is globally configured.
4. Cache mechanism compared to Hibernate cache
Hibernate level 1 cache is a Session cache. To make good use of the level 1 cache, you need to manage the life cycle of the Session. It is recommended to use a Session in an Action. Level 1 caching requires strict Session management.
Hibernate L2 cache is a SessionFactory cache. SessionFactory cache is divided into built-in cache and external cache. The built-in cache stores data contained in some of the collection properties of the SessionFactory object (mapping elements, predefined SQL statements, etc.), which is read-only for applications. An external cache stores copies of database data, similar to a level 1 cache. In addition to memory as a storage medium, secondary cache can also be selected external storage devices such as hard disks. The second-level cache is called a process-level cache or SessionFactory cache, which can be shared by all sessions, and its life cycle exists and dies along with the life cycle of the SessionFactory.
5. Advantage comparison
Mybatis Advantage
MyBatis allows for more granular SQL optimization and reduces the number of query fields.
MyBatis is easy to master, while Hibernate has a higher threshold.
Hibernate Advantage
Hibernate's DAO layer is simpler to develop than MyBatis, which requires maintenance of SQL and result mappings.
Hibernate is better at object maintenance and caching than MyBatis, and it is easier to maintain objects that are added, deleted, and searched.
Hibernate database portability is very good, MyBatis database portability is not good, different databases need to write different SQL.
Hibernate has a better second-level caching mechanism and can use third-party caching. MyBatis itself provides a poor caching mechanism.
Willing to understand the framework technology or source code friends directly plus please (penguin): 2042849237
More detailed source code reference source: http://×××/technology
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.