Pros and cons of MyBatis vs Hibernate

Source: Internet
Author: User

Benefits of Hibernate:

1, hibernate is fully automatic, hibernate can completely through the object relational model to achieve the operation of the database, with a complete JavaBean object and database mapping structure to automatically generate SQL.

2, powerful, database-independent, O/R mapping ability, need to write a few code, the development speed is very fast.

3, there is a better level of two cache mechanism, you can use a third-party cache.

4. Good portability of database.

5, Hibernate has a complete log system, Hibernate log system is very sound, involving a wide range, including SQL records, relationship anomalies, optimization warnings, cache hints, dirty data warning, etc.

The disadvantage of Hibernate:

1, the learning threshold is high, the proficiency threshold is higher, the programmer how to design O/R mapping, how to balance the performance and the object model, and how to use good hibernate experience and ability are very strong.

2, hibernate SQL Many are automatically generated, can not directly maintain SQL, although there are hql query, but the function is not as strong as SQL, see reports and other abnormal requirements, HQL query to virtual, that is HQL query is limited Hibernate also supports native SQL queries, but the development pattern is different from ORM and requires switching thinking, so it is inconvenient to use. In short, the flexibility of writing SQL on Hibernate is less than MyBatis.

Advantages of MyBatis:

1, easy to get started and mastered, provides the database query automatic object binding function, and continues the very good SQL use experience, for not so high object model requirements of the project, quite perfect.

2, SQL written in XML, easy to unified management and optimization, the decoupling of SQL and program code.

3, provide mapping label, support ORM field relationship mapping between object and database

4, provide the object relation mapping tag, support the object relation establishment maintenance

5, provide XML tags, support to write dynamic SQL.

6. Faster speed relative to hibernate

Disadvantages of MyBatis:

1, the association table A long time, many fields, SQL workload is very large.

2, SQL relies on the database, resulting in poor migration of the database.

3. Because the tag ID in XML must be unique, method overloading is not supported in DAO.

4, the object Relation mapping label and the field map label are only the description of the mapping relationship, the implementation still relies on SQL.

5, DAO layer is too simple, the workload of object assembly is larger.

6, Cascade Update, cascade Delete is not supported.

7, MyBatis Log In addition to the basic record function, other functions are weak.

8, when writing dynamic SQL, debugging is not convenient, especially when the logic is complex.

9, the provision of dynamic SQL XML tag is simple, writing dynamic SQL is still limited, and low readability.

Pros and cons of MyBatis vs Hibernate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.