Hibernate and compare the advantages and disadvantages Mybatis

Introduction:

  Hibernate : Hibernate is the most popular ORM framework, the database structure provides a more complete package.

  Mybatis : Mybatis is also very popular ORM framework, the main focus is to map the relationship between POJO and SQL.

Specifically talk about several aspects of difference between the two:

1. The biggest difference between the two:

  For simple logic, Hibernate MyBatis and have corresponding code generator can generate simple basic DAO layer method.

  For advanced queries, Mybatis need to manually write SQL statements, and ResultMap. Hibernate mapping and have a good mechanism, developers do not need to care about SQL generation and map the results, you can focus more on business processes.

2. Develop difficulty contrast

  Hibernate development difficulty is greater than Mybatis. Mainly due to Hibernate relatively complex, large, long learning curve.

  The Mybatis is relatively simple, and Mybatis mainly depends on the writing sql, allowing developers to feel more familiar.

3.sql written Compare

  Mybatis of SQL is written in the manual, so you can specify fields queries on demand. But not have their own log statistics, so to help log4j for logging.

  Hibernate can also write your own SQL query to specify the fields that need, but it undermines the simplicity Hibernate development. However, Hibernate has its own log statistics.

4. The database comparison extension

  Mybatis Since all SQL databases are dependent on writing, so relatively poor scalability, mobility.

  Hibernate specifically associated with a database in XML, so what is the specific HQL database is not very concerned about.

5. Compare caching mechanism

  The same point: Hibernate second-level cache and Mybatis In addition to using the default caching mechanism, but can be achieved through your own cache or other third-party caching scheme, create an adapter completely override the cache behavior.

  Different points: Hibernate secondary cache configuration disposed in detail SessionFactory generated configuration file, and then in particular table - that configuration is cached object map.

  MyBatis secondary cache are arranged in each particular table - the object mapping in detail the configuration, this can customize different tables for different caching mechanism. And Mybatis cache configuration can share the same namespace and examples, achieved by Cache-ref.

  Compare the two : because Hibernate has a good management system to query objects, users do not care about SQL. Therefore, the use of dirty data if the secondary cache, the system will report an error occurs and tips.

The MyBatis In this regard, special care needs when using the L2 cache. If you can not fully determine the scope of the data update operations spread, to avoid the blind use of Cache. Otherwise, the normal operation of the system of dirty data will appear a great deal of risk.

6. Summary:

  mybatis: compact, convenient, efficient, simple, direct, semi-automatic
  hibernate: powerful, convenient, efficient and complex, roundabout, automatic

  Hibernate and MyBatis can be generated by SessionFactoryBuider by the XML configuration file SessionFactory, and then generate a SessionFactory Session, and finally to open execute transactions, and SQL statements by the Session.

  The advantage is that MyBatis MyBatis can be more detailed SQL optimization can reduce query field, and easy to grasp.

  Hibernate DAO layer development advantage is simpler than MyBatis, Mybatis need to maintain SQL and result mapping. The database is very portable, MyBatis database portability is not good, different databases need to write a different SQL. Have a better secondary cache mechanism, you can use third-party caching. MyBatis poor caching mechanism itself provides.

mybatis:

  1. Getting started is simple, with a school that provides automatic object database query binding function, but also a continuation of a very good experience with SQL, not so high for the project object model requirements, it quite perfect.

  2. Can be more detailed SQL optimization can reduce query field.

  3. drawback is that the framework is quite simple, there are features missing, although simplifies data binding code, but the whole actual underlying database queries still have to write your own workload is relatively large, but not easy to adapt to rapid database modifications.

  4. Poor secondary cache mechanism.

hibernate:

  1. powerful, database-independent, good, strong O / R mapping capabilities, if you are quite proficient Hibernate, but also for Hibernate were properly package, then your entire project persistence layer code is quite simple, you need to write the code is less developed very fast, very cool.

  2. have a better secondary cache mechanism, you can use third-party caching.

  3. drawback is that learning threshold is not low, to master a higher threshold, and how design O / R mapping, how to weigh the balance between performance and object model, and how to make good use of Hibernate required aspects of your experience and capabilities are strong the job.

For a vivid metaphor:

  the mybatis : machine tools, easy to use, used to use, but still have to work to make, but the tool is live, how to make the decision for me.

  Hibernate : intelligent robots, but it is very high research and development (learning, proficiency) cost, and work to get rid of him, but it is limited to what you can do.



Reference: https://blog.csdn.net/qq_41378597/article/details/88070335

 

Guess you like

Origin www.cnblogs.com/116970u/p/11447441.html