由于java视频里以前好多都是SSH。但是在实际工作中没见过用hibernate的,基本都用mybatis。
我有一些疑问:
hibernate碰到什么样的业务会变成致命的弱点,都说hibernate效率低,能否举个例子(例如同一个查询用mybatis查询耗时1秒,用hibernate查询耗时10秒)
可能是有部分人遇到了hibernate的瓶颈,但是这部分人的业务量我觉得,不是大部分使用hibernate的人都能遇到的。一般的小项目,不超过100个用户,这样的项目综合考虑的话更适合用mybatis还是hibernate?主要从开发效率上来说的话。为什么?
天蓬老师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.
大家讲道理2017-04-18 09:34:16
hibernate
适合于都是单表的增删改差,开发效率很高,可是一旦业务扩展或者当初db
设计不好,需要连表查询(因为hibernate的思想是对表的类化,但实际生活中要做到完全的类化在一个项目刚开始的时候是不容易做到的)不同的结果再加上删选匹配的话效率就会下降(除非你写sql,但是这样一来还不如一开始用mybatis),尤其再遇到大数据量,效率成倍数下降。
不超过100个用户?,这里的数量级不是按单表算的,单表如果超过一定数据量也不是简单选用hibernate
或mybatis
能解决的,只能说如果用mybatis
的话比较好改而已。就我经验,如果涉及大量连表查询且业务复杂的时候(通常项目到最后都是如此)最好用mybatis
,简单的还是hibernate
快一些(开发效率
)
伊谢尔伦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
天蓬老师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.
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.
伊谢尔伦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).
伊谢尔伦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.
黄舟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.
伊谢尔伦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.