The difference between Mybatis and Hibernate

hibernate : is a standard ORM framework (Object Relational Mapping). The entry threshold is relatively high, there is no need to write SQL, and SQL statements are automatically generated, so it is difficult to optimize and modify SQL statements.

Application scenario: suitable for small and medium-sized projects with little change in requirements, such as: background management system, erp, orm, oa, etc.


mybatis: Focus on sql itself. Programmers need to write sql statements by themselves. It is more convenient to modify and optimize sql. Mybatis is an incomplete ORM framework. Although programmers write sql themselves, mybatis can also implement mapping (input mapping, output mapping)

Application Scenario: Applicable to projects with changing needs, such as Internet projects.


Same point :

( 1) Both Hibernate and MyBatis use SessionFactoryBuider to generate SessionFactory from XML configuration file, SessionFactory generates Session, and Session is used to start executing transactions and SQL (Structured Query Language) statements.

(2) Both Hibernate and MyBatis support JDBC (Java DataBase Connectivity, java database connection) and JTA (Java Transaction API, Java Transaction API ( Application Programming Interface, application programming interface) ) transaction processing.

Note: The main role of jdbc and jta is to enhance data access capabilities.

(3) Based on the idea of ​​ORM (Object Relational Mapping , object relational mapping ) , the mapping problem between entity and database is solved


difference:

(1) SQL: Mybaits maintains the mapping results through mapper.xml. Compared with hibernate’s automatic generation of hql (hibernate sql), it is more flexible for programmers to manually write sql, and the sql tuning is easier (hibernate has better encapsulation and improved development efficiency. At the same time, sql statement tuning is more laborious, of course, you can manually modify sql to optimize, but it will also affect the development efficiency); hibernate's hql database has better portability, which is reflected in its robustness. Hibernate is inefficient in cascading deletion; when the amount of data is large and there are many tables, operations based on relationships will become complicated.

(2) In terms of caching: both mybatis and hibernate can use third-party caching, and hibernate has a better secondary caching mechanism than maybatis.


Enterprises carry out technology selection, take low cost and high return as the principle of technology selection, and select models according to the technical strength of the project.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325390030&siteId=291194637