The difference between Mybatis and Hibernate, advantages and disadvantages, application scenarios

The difference between Mybatis and Hibernate

Mybatis technical characteristics:

benefit

  1. By directly writing SQL statements, you can directly optimize SQL performance;
  2. Low learning threshold and low learning cost. As long as you have a SQL foundation, you can learn mybatis, and it is easy to learn;
  3. Because the SQL statement is written directly, it is flexible and changeable, and the code maintainability is better.

Disadvantage

  1. Cannot support database independence, that is, if the database changes, it is necessary to write multiple sets of codes to support it, and portability is not good.
    For example, the syntax of different databases may be different, (paged) Mysql: limit, Oracle: rownum
  2. Need to write result mapping.

Hibernate technical characteristics:

benefit

  1. Standard orm framework (Object Relational Mapping), programmers do not need to write SQL statements.
  2. It has good database independence, that is, if the database changes, the code does not need to be written again.
    Such as: mysql data is migrated to oracle, only the dialect configuration needs to be changed

Disadvantages:

  1. The learning threshold is high, and you need to have a good foundation for the data relationship model (one-to-many, many-to-one, many-to-many, one-to-one), and when setting up OR mapping, you need to consider the trade-off between performance and object model.
  2. Programmers cannot optimize SQL performance independently.

Mybatis application scenarios:

Internet projects with changing needs , such as e-commerce projects.

Hibernate application scenarios:

Projects with clear needs and fixed business , such as OA projects (Office Automation projects), ERP projects (Enterprise Resource Planning (Enterprise Resource Planning) large-scale enterprise management information projects), etc.

Guess you like

Origin blog.csdn.net/qq_43414199/article/details/108795395