Mybatis contrast with Hibernate

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/projim_tao/article/details/102633617

introduction

MyBatis and Hibernate are all O / R Mapping solutions, both applications are very wide, so what exactly they same and different, how to choose the practical application of it? I've used MyBatis and Hibernate, following only my personal feeling on use to sum up the similarities and differences between the two:

First, the similarities

  • Both are one kind of O / R Mapping solutions, are common persistence framework
  • Common framework for both can be better integrated with the spring, etc.
  • Probably both use similar processes are generally as follows:
  1. Hibernate configuration files or create MyBatis, MyBatis / Hibernate for initialization by the profile. Configuration and mapping files including configuration database
  2. Create a mapping file, each table corresponding to a map data file that describes the information tables in the database, the corresponding information is also described a persistent class;
  3. Create a persistent class, each class corresponding to a database table, by associating a map file.
  4. DAO layer written and then write the code Service layer based on business

Second, the difference

  • MyBatis more compact compared with Hibernate, easy to use, especially for those on the original sql familiar friend;
  • MyBatis is direct SQL-based, it requires developers to write their own specific SQL statement, it will use these SQL statements to query the database, and then by mapping configuration file, SQL parameters required and the results returned to the field mapping specified in POJO . It is because of MyBatis SQL is written entirely by the developer, so the higher its flexibility; Hibernate is relatively relatively heavyweight, is more complex, but relatively high degree of automation, packaging stronger, more can be said to be object-oriented, does not require developers to write their own SQL statements, you can use automated tools supporting development.
  • Since MyBatis direct SQL-based, middle of the process is relatively small, so the relative hibernate, its running faster. Of course if it is relatively standard CURD operation, can significantly reduce the amount of code written using hibernate, but if you want to be more flexible control query for SQL optimization and other operations, then choose MyBatis would be better.

Guess you like

Origin blog.csdn.net/projim_tao/article/details/102633617