[mybatis] comparison between mybatis and Hibernate


1. The difference between mybatis and Hibernate

1.1 table comparison

function MyBatis Hibernate
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

1.2 similarities

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

  1. The advantage of Batis is that it can reduce the number of query fields.
  2. Hibernate has the advantage that Dao layer development is simpler than mybatis, and mybatis needs to maintain SQL and result mapping.
  3. Hibernate database portability is very good, mybatis database portability is not good, different databases need to write different SQL.
  4. Hibernate has a better secondary caching mechanism, which can use third-party caching. Mybatis itself provides a poor caching mechanism.

Recommended Today

Regular expression analysis of PHP matching multiple lines

Copy codeThe code is as follows: <table> <tr><td>aaaa</td></tr> <tr><td>bbbb</td></tr> <tr><td>cccc</td></tr> <tr><td>dddd</td></tr> </table> How to match text like this with PHP regular expressions??My first thought:Pattern: “/ < tr > [. N] *? < \ / TR >” (this is wrong)Idea: “can match any non newline character, use the” [. [n] “combination, so that it can match […]