Hibernate&MyBatis different

I. Introduction Framework

        hibernate is a good ORM framework (object-relational hint), the height of the package sql statement and table relationships, developers only need to configure relations imply a good table and pojo class, there are tables and tables, classes and class-many , many to one, one to one relationship. How the developers do not need to write the sql statement, to focus on the business logic yes.

     mybatis is also a good ORM framework, but with respect to hibernate it is relatively simple, he just jdbc package, as well as relationships between tables sql statement had to own one mapping.

Second, the framework uses

        1) hibernate after configuring the relationship, the object can be directly manipulated, let's use the session object crud way to achieve operation of the database, and mybatis you need to manually write sql statement, such a contrast, hibernate development speed is superior to mybatis but at the same time there have been problems in the face of some advanced query, hibernate is a bit powerless, hibernate sql statement is written dead, sometimes some of the fields we do not need to query or modify, but his package was all that while we can set the field manually, but it destroyed the simplicity of hibernate. The mybatis you can write your own manual sql optimization, and dynamic sql functions can be optimized sql.

    2) hibernate has its own caching mechanism, mybatis do not, and now most are using third-party caching, so this advantage has been erased.

    3) hibernate heavyweight relatively high barriers to entry, and is lightweight package mybatis JDBC, it can be off now.

Third, the summary

    1) hibernate suitable for single operating table, can not be optimized sql, not suitable for high concurrent development project for the development OA.CRM projects.

   2) sql statement mybatis of flexibility for developing Internet projects.


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Hibernate advantages:

. 1, hibernate is fully automatic, hibernate can achieve operation of the database by object-relational model, it has a complete mapping structure JavaBean objects to automatically generate database sql.

2, powerful, database-independent, good, strong O / R mapping capabilities, need to write less code, develop fast.

3, there is a better secondary cache mechanism, you can use third-party caching.

4, database portability is good.

5, hibernate has a complete log system, hibernate logging system is very sound, cover a wide range, including sql records, abnormal relations, optimizing warning, prompt caching, dirty warnings

Hibernate cons:

1, high learning curve, higher proficiency threshold, how programmers design O / R mapping, how to strike a balance between performance and object models, as well as how to use Hibernate good experience and capabilities required aspects of the job are strong

2, a lot of sql hibernate are automatically generated and can not directly maintain sql; although there are hql inquiry, but the function is still not as powerful sql, reports, etc. to meet the needs of metamorphosis, hql inquiry to virtual, there is a limitation that is hql inquiry of; hibernate although support native sql queries, but the development model but with different orm, thinking needs to be converted, so the use of some inconvenience. In short write sql hibernate less mybatis on flexibility.

Mybatis advantages:

1, easy to use and master, provides automatic object database queries binding function, but also a continuation of a very good experience with SQL, not so high for the project object model requirements, it quite perfect.

2, sql written in xml, to facilitate unified management and optimization decouples sql and program code.

3, to provide maps label, field support orm object-relational mapping database

4, provide object-relational mapping label, set up to support object-relational maintenance

5, providing xml tags, support the preparation of dynamic sql.

6, the speed is faster with respect to Hibernate

Mybatis disadvantages:

1, associated table for a long time, and more time fields, great sql workload.

2, sql dependent on the database, resulting in poor portability database.

3, due in xml tag id must be unique, leading to the DAO method does not support method overloading.

4, object-relational mapping field mapping tags and labels is a description of the mapping relationship, dependent on the specific implementation still sql.

5, DAO layer is too simple, large objects assembled workload.

6, does not support cascading update, delete cascade.

7, Mybatis log in addition to the basic recording functions, a lot of other functions weak.

8, when writing dynamic sql, convenient debugging, especially when complex logic.

9, provides dynamic sql write the xml tag function is simple, write dynamic sql is still limited, and low readability.

Guess you like

Origin www.cnblogs.com/Dfrank/p/11653809.html