Home > Back-end > The advantages and disadvantages of MyBatis and Hibernate.
The advantages and disadvantages of MyBatis and Hibernate.
Time:12-02
Hibernate's advantages:
1, hibernate is fully automatic, hibernate can completely through implementation to the operation of the database object relational model, has a complete JavaBean objects and the mapping structure to automatically generate the SQL database,
2, powerful, good database independence, O/R mapping capability is strong, rarely need to write the code, the development of fast,
3, the better the second level cache mechanism, can use third party cache,
4, good database portability,
5, hibernate has complete log system, hibernate log system is very perfect, wide-ranging, including SQL records, relationship is unusual, optimize the warning, cache hits, dirty data warned such as
Hibernate drawback:
1, high threshold, acquire a good knowledge of the threshold is higher, the programmer how to design the O/R mapping, how to achieve a balance between performance and the object model, and how to use a good Hibernate's experience and ability are strong do
2, hibernate SQL many are automatically generated, cannot maintain SQL directly; Despite HQL query, but still not as good as SQL powerful, meet the abnormal demand such as reports, HQL query to empty, that is to say HQL query is limited; Hibernate while also supports native SQL queries, but unlike the orm, development mode need to transform the thinking, so use some inconvenient, in a word written on the flexibility of SQL hibernate as mybatis,
The advantages of Mybatis:
1, easy to learn and master, and provide the function of automatic object binding database query, and continued the good experience in using SQL, for projects which do not require high object model, is quite perfect,
2, write SQL with XML, facilitate unified management and optimized, remove SQL code with coupling,
3, provide the map tag, relational mapping support objects and database orm field
4, to provide object relational mapping labels, support object relational form maintenance
5, provide XML tags, support dynamic SQL,
6, the speed relative to Hibernate fast
Mybatis drawback:
More than 1, the associative table, fields, SQL workload is very big,
2, dependent on the database SQL, leading to poor database portability,
3, because the XML tags id must be unique, does not support method overloading, which results in the DAO methods,
4, object relational mapping tag and field mapping is just a description of the mapping relationship, the concrete implementation still relies on SQL,
5, DAO layer is too simple, object assembly larger workload,
6, do not support cascading updates, cascading deletes,
7, Mybatis log records in addition to basic function, other functions weak many,
Eight, write dynamic SQL, not convenient debugging, especially in the complex logic,
9, provide write simple dynamic SQL XML tags, write dynamic SQL is still limited, and readability is low,