search

Home  >  Q&A  >  body text

java - 关于mybatis和hibernate的困惑

谢谢

巴扎黑巴扎黑2805 days ago1632

reply all(19)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 09:34:16

    You can try: http://www.oschina.net/p/monalisa-core It is more convenient to use with the Eclipse plug-in:

    • Supports automatic generation of DTO

      SQL query does not need to write DTO like Mybatis, and then configure a bunch of field mappings. The plug-in does it all automatically for you.
      Reference article: How to automatically generate DTO based on dynamic SQL code

    • Multi-line string syntax

      Writing multi-line strings in Java code becomes very easy.

    • DataTable operations

      DataTable can be used to query database tables with some convenient field selection, filtering, aggregation, grouping, JOIN, etc.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:34:16

    hibernate适合于都是单表的增删改差,开发效率很高,可是一旦业务扩展或者当初db设计不好,需要连表查询(因为hibernate的思想是对表的类化,但实际生活中要做到完全的类化在一个项目刚开始的时候是不容易做到的)不同的结果再加上删选匹配的话效率就会下降(除非你写sql,但是这样一来还不如一开始用mybatis),尤其再遇到大数据量,效率成倍数下降。
    不超过100个用户?,这里的数量级不是按单表算的,单表如果超过一定数据量也不是简单选用hibernatemybatis能解决的,只能说如果用mybatis的话比较好改而已。就我经验,如果涉及大量连表查询且业务复杂的时候(通常项目到最后都是如此)最好用mybatis,简单的还是hibernate快一些(开发效率

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:34:16

    The learning cost of hibernate is relatively high, but there are JPA specifications in j2ee, and learning the specifications is okay. Mybatis is relatively simple, easy to use and controllable. Hibernate has high learning costs, is overly object-oriented, and is difficult to tune. As for the use, it depends on the individual. For toB or toC applications, I prefer mybatis, but for management backend, hibernate is fine

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:34:16

    Thanks for the invitation! The following answers are all very good. First, MyBatis is easy to learn. Second, it is flexible and easy to control by directly writing SQL. As for performance, it is not the focus. Development efficiency and maintainability are much more important than performance.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:34:16

    hiberbate uses java objects to write sql, while mybatis writes native sql directly. The former is fun to develop for a while and maintains the crematorium (modification); the latter requires a certain understanding of SQL knowledge (compared to the former). If the company has a DBA, it is much more intuitive for him to read native SQL than Java code. As for performance, in most cases there is no need to consider it (if you really want to consider it, you can search for "removing ORM" that some people have discussed in recent years). The most important thing is maintainability.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:34:16

    hibernate and mybatis are just encapsulation of JDBC. Whether the program performance is good or not depends mainly on whether the SQL is well written and whether the DB design is reasonable. Of course, many SQLs in hibernate are implemented programmatically. If both frameworks are Proficient, there shouldn't be much difference in performance when used. Then the problem comes. Hibernate is too encapsulated. It is actually quite difficult to be proficient. Mybatis is just a simple encapsulation of jdbc, with low learning cost, and hibernate uses SQL in many scenarios. It is encapsulated. If you are not particularly proficient, sometimes the programs you write will have unexpected situations. Mybatis is simpler and does not do too much, so the results of the program are usually easier to predict. question.
    The designs of both frameworks are actually excellent, but personal usage habits are more important. People who are used to mybatis will generally have a hard time switching to hibernate. On the other hand, if people are really proficient in hibernate, they probably won’t deliberately use mybatis( My humble opinion).

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:34:16

    The use of Mybatis in actual work is basically not based on performance or usability considerations, but based on personal habits.
    Old programmers like us are used to writing SQL, and would feel uncomfortable if we don’t write it. In contrast, hibernate that is too automated will make us panic.
    That’s all.

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:34:16

    Having used it during the learning stage, my personal feeling is that hibernate is too encapsulated. Many times it feels like it does not bring convenience, but that I have to do some seemingly unnecessary operations in order to "coordinate" with this framework.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:34:16

    If the business volume is relatively small, it depends on which one you are more proficient in. It will be all right. No need to worry about this. Mybatis is more flexible, giving developers more room for their own implementation. The hibernate association should be the reason why it is slightly slower.

    reply
    0
  • Cancelreply