1. The difference between mybatis and Hibernate
1.1 table comparison
|Development speed||Easy to use||Relatively difficult to master|
|development effort||Handwritten SQL statement||You can also write SQL statements, but it breaks hibernate encapsulation and simplicity|
|Expansibility||Because it is handwritten SQL, all scalability is good, but migration is poor||Database relational association is all in XML, so HQL doesn’t care what kind of database it is|
|Portability||Not good. Write different SQL for different databases||preferably|
|First level cache||SQLSession||Session cache|
|L2 cache||Detailed configuration is performed in each specific table object mapping||Detailed configuration is performed in the configuration file generated by sessionfactory,
Then configure the cache in the specific table object mapping
Both hibernate and mybatis can generate sessionfactory from XML configuration file through sessionfactorybuilder, and then generate session by sessionfactory. Finally, session is used to start the execution of transactions and SQL statements.
1.3 differences between the two
- The advantage of Batis is that it can reduce the number of query fields.
- Hibernate has the advantage that Dao layer development is simpler than mybatis, and mybatis needs to maintain SQL and result mapping.
- Hibernate database portability is very good, mybatis database portability is not good, different databases need to write different SQL.
- Hibernate has a better secondary caching mechanism, which can use third-party caching. Mybatis itself provides a poor caching mechanism.