The difference between hibernate and mybatis

1. hibernate is fully automatic, while mybatis is semi-automatic.
Hibernate can completely realize the operation of the database through the object relational model, and has a complete mapping structure between the JavaBean object and the database to automatically generate sql. While mybatis only has basic field mapping, object data and the actual relationship of objects still need to be implemented and managed by handwritten sql.
2. The portability of hibernate database is much greater than that of mybatis.
Hibernate greatly reduces the coupling between objects and databases (oracle, MySQL, etc.) through its powerful mapping structure and hql language, while mybatis requires handwritten sql, so the coupling with the database directly depends on the programmer's method of writing sql, If SQL is not universal and many SQL statements with certain database characteristics are used, the portability will be greatly reduced, and the cost will be high.
3. Hibernate has a complete logging system, while mybatis lacks some.
The hibernate log system is very sound and covers a wide range, including: sql records, relational exceptions, optimization warnings, cache hints, dirty data warnings, etc.; while mybatis has much weaker functions in addition to basic logging functions.
4. Compared with hibernate, mybatis needs to care about many details
. The configuration of hibernate is much more complicated than that of mybatis, and the learning cost is higher than that of mybatis. But it is precisely because mybatis is simple to use that it cares more about technical details than hibernate. Because mybatis does not need to consider many details, the development mode is very different from traditional jdbc, so it is easy to get started and develop projects, but ignoring details will lead to many bugs in the early stage of the project, so it is very slow to develop relatively stable software, and the development of software But soon. Hibernate is just the opposite. But if you are proficient in using hibernate, in fact, the development efficiency is no worse than or even surpasses mybatis.
5. In terms of direct sql optimization, mybatis is much more convenient than hibernate.
Since the sql of mybatis is written in xml, optimizing sql is much more convenient than hibernate. However, many of hibernate's sql are automatically generated and cannot be directly maintained; although there is hql, its functions are still not as powerful as sql. When seeing abnormal needs such as reports, hql also stops, which means that hql has limitations; hibernate Although native sql is also supported, the development mode is different from orm, and it needs to change the thinking, so it is not very convenient to use. In short, hibernate is not as flexible as mybatis in writing sql.

Guess you like

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