我对hibernate和mybatis框架的比較
系统在选择操作数据库的框架上面,究竟是选择hibernate,还是mybatis。
首先说下两者的原理,假设你要关联几张表做查询,查出20条记录:
1.假设是mybatis
SELECT *
FROM (SELECT INNER_TABLE.*, ROWNUM OUTER_TABLE_ROWNUM
FROM (select SP_WORK_PLAN.name, sprocorgan1_.code --仅仅是查询
from SP_WORK_PLAN workplanvo0_,
v_sp_organization sprocorgan1_,
V_SP_USER sprocuserv2_,
v_sp_organization sprocorgan3_,
V_SP_USER sprocuserv4_,
V_SP_USER sprocuserv5_,
v_sp_organization sprocorgan6_
from workplanvo0_.APPLY_DEPARTMENT_OID =
sprocorgan1_.ORG_ID and
workplanvo0_.CONFIRMATION_UID = sprocuserv2_.USER_ID and
sprocuserv2_.ORG_ID = sprocorgan3_.ID and
workplanvo0_.CREATE_UID = sprocuserv4_.USER_ID and
workplanvo0_.WORK_MASTER_UID = sprocuserv5_.USER_ID and
workplanvo0_.WORK_TEAM_ID = sprocorgan6_.ORG_ID) INNER_TABLE
WHERE ROWNUM <= 20) OUTER_TABLE
WHERE OUTER_TABLE_ROWNUM > 0;
2.假设是hibernate,像以下的SQL要查20次。
select
workplanvo0_.ID as ID9_6_,
workplanvo0_.UPDATE_TIME as UPDATE2_9_6_,
workplanvo0_.OPTIMISTIC_LOCK_VERSION as OPTIMISTIC3_9_6_,
workplanvo0_.CODE as CODE9_6_,
workplanvo0_.DATA_FROM as DATA5_9_6_,
workplanvo0_.DATA_STATE as DATA6_9_6_,
workplanvo0_.END_LIFECYCLE as END7_9_6_,
workplanvo0_.NAME as NAME9_6_,
workplanvo0_.START_LIFECYCLE as START9_9_6_,
workplanvo0_.FLOW_STATE as FLOW10_9_6_,
workplanvo0_.PROCESS_INS_ID as PROCESS11_9_6_,
workplanvo0_.ACTUAL_END_TIME as ACTUAL12_9_6_,
workplanvo0_.ACTUAL_START_TIME as ACTUAL13_9_6_,
workplanvo0_.APPLY_DEPARTMENT_OID as APPLY40_9_6_,
workplanvo0_.ATTENTION_LEVEL as ATTENTION14_9_6_,
workplanvo0_.COMPLETE_CONDITION as COMPLETE15_9_6_,
workplanvo0_.CONFIRMATION_TIME as CONFIRM16_9_6_,
workplanvo0_.CONFIRMATION_UID as CONFIRM41_9_6_,
workplanvo0_.CREATE_UID as CREATE42_9_6_,
sprocorgan1_.ID as ID26_0_,
sprocorgan1_.UPDATE_TIME as UPDATE2_26_0_,
sprocorgan1_.OPTIMISTIC_LOCK_VERSION as OPTIMISTIC3_26_0_,
sprocorgan1_.CODE as CODE26_0_,
sprocorgan1_.DATA_FROM as DATA5_26_0_,
sprocorgan1_.DATA_STATE as DATA6_26_0_,
sprocorgan1_.END_LIFECYCLE as END7_26_0_,
sprocorgan1_.NAME as NAME26_0_,
sprocorgan1_.START_LIFECYCLE as START9_26_0_,
sprocorgan1_.AREA_ID as AREA10_26_0_,
sprocorgan1_.STATE as STATE26_0_,
sprocuserv2_.ID as ID27_1_,
sprocuserv2_.UPDATE_TIME as UPDATE2_27_1_,
sprocuserv2_.OPTIMISTIC_LOCK_VERSION as OPTIMISTIC3_27_1_,
sprocuserv2_.CODE as CODE27_1_,
sprocuserv2_.DATA_FROM as DATA5_27_1_,
sprocuserv2_.DATA_STATE as DATA6_27_1_,
sprocuserv2_.END_LIFECYCLE as END7_27_1_,
sprocuserv2_.NAME as NAME27_1_,
sprocuserv2_.START_LIFECYCLE as START9_27_1_,
sprocuserv2_.ACCOUNT as ACCOUNT27_1_,
sprocorgan3_.ID as ID26_2_,
sprocorgan3_.UPDATE_TIME as UPDATE2_26_2_,
sprocorgan3_.OPTIMISTIC_LOCK_VERSION as OPTIMISTIC3_26_2_,
sprocorgan3_.CODE as CODE26_2_,
sprocorgan3_.DATA_FROM as DATA5_26_2_,
sprocorgan3_.DATA_STATE as DATA6_26_2_,
sprocuserv4_.ID as ID27_3_,
sprocuserv4_.UPDATE_TIME as UPDATE2_27_3_,
sprocuserv4_.OPTIMISTIC_LOCK_VERSION as OPTIMISTIC3_27_3_,
sprocuserv4_.CODE as CODE27_3_,
sprocuserv4_.DATA_FROM as DATA5_27_3_,
sprocuserv4_.DATA_STATE as DATA6_27_3_,
sprocuserv4_.END_LIFECYCLE as END7_27_3_,
sprocuserv4_.NAME as NAME27_3_,
sprocuserv5_.ID as ID27_4_,
sprocuserv5_.UPDATE_TIME as UPDATE2_27_4_,
sprocuserv5_.OPTIMISTIC_LOCK_VERSION as OPTIMISTIC3_27_4_,
sprocuserv5_.CODE as CODE27_4_,
sprocuserv5_.DATA_FROM as DATA5_27_4_,
sprocuserv5_.DATA_STATE as DATA6_27_4_,
sprocuserv5_.END_LIFECYCLE as END7_27_4_,
sprocorgan6_.ID as ID26_5_,
sprocorgan6_.UPDATE_TIME as UPDATE2_26_5_,
sprocorgan6_.OPTIMISTIC_LOCK_VERSION as OPTIMISTIC3_26_5_,
sprocorgan6_.CODE as CODE26_5_,
sprocorgan6_.DATA_FROM as DATA5_26_5_,
sprocorgan6_.DATA_STATE as DATA6_26_5_,
sprocorgan6_.END_LIFECYCLE as END7_26_5_,
sprocorgan6_.NAME as NAME26_5_,
sprocorgan6_.START_LIFECYCLE as START9_26_5_,
sprocorgan6_.STATE as STATE26_5_
from
SP_WORK_PLAN workplanvo0_
left outer join
v_sp_organization sprocorgan1_ on workplanvo0_.APPLY_DEPARTMENT_OID=sprocorgan1_.ORG_ID
left outer join
V_SP_USER sprocuserv2_ on workplanvo0_.CONFIRMATION_UID=sprocuserv2_.USER_ID
left outer join
v_sp_organization sprocorgan3_ on sprocuserv2_.ORG_ID=sprocorgan3_.ID
left outer join
V_SP_USER sprocuserv4_ on workplanvo0_.CREATE_UID=sprocuserv4_.USER_ID
left outer join
V_SP_USER sprocuserv5_ on workplanvo0_.WORK_MASTER_UID=sprocuserv5_.USER_ID
left outer join
v_sp_organization sprocorgan6_ on workplanvo0_.WORK_TEAM_ID=sprocorgan6_.ORG_ID
where workplanvo0_.ID=? ;
1.设计阶段的影响
无法验证模型的合理性和预測性能。依据界面原型做数据库设计,长处是能够保证数据都能存到数据中,不足之处是无法保证模型的合理和性能。
假设调整架构用ibatis,我们能够在设计完毕后,写代码之前把复杂的查询写出来,制造一些数据进行性能预測。
2.开发阶段的影响
a.Hibernate无法使用层次查询、分析函数、正則表達式等。不错。hibernate有调用SQL的结果。假设通过接口调用SQL,不便于调试,用ibatis很适合调试。
b.在开发阶段也无法预測性能,就是測试SQL。
c.hibernate的内部实现比較复杂。假设没有人能读懂里面的源码。最好是仅仅使用最简单的增、删、改。查(依据主键查)。反观mybatis,实现非常easy。hold住。
3.运维阶段的影响
在运维阶段每天监控数据库,找到性能隐患,是业界的最佳实践。
假设是hibernate的架构,即使我们找出了问题SQL,也无法对修改SQL进行调优。由于它是生成处理的。最多加一个索引。
最后:所实用hibernate对DB操作。把hibernate当做一个SQL生成的工具。事实上就是把数据库当做一个黑盒。好像不须要对它有深入的了解,这样是被误导,看看我们如今有些组开发的报表开发工具,假设遇到大数据量,往往歇菜。
我对hibernate和mybatis框架的比較的更多相关文章
- Hibernate和Mybatis框架的对比
Hibernate:是一个标准的ORM(对象关系映射)框架.入门门槛较高,不需要程序员写sql,sql语句自动生成.但是就造成对sql语句进行优化.修改比较困难.应用场景:适用于需求变化不多的中小型项 ...
- 【JAVA框架】Hibernate 与Mybatis 区别
Hibernate Mybatis 简介 区别 与联系 欢迎提出见解及转载. 1 简单简介 1.1 Hibernate 框架 Hibernate是一个开放源代码的对象关 ...
- Hibernate框架与Mybatis框架的对比
学习了Hibernate和Mybatis,但是一直不太清楚他们两者的区别的联系,今天在网上翻了翻,就做了一下总结,希望对大家有帮助! 原文:http://blog.csdn.net/firejuly/ ...
- 持久化ORM框架——Hibernate与mybatis
最初SUN公司推出了JavaEE服务器端组件模型(EJB),但是由于EJB配置复杂,且适用范围较小,于是很快就被淘汰了.与EJB的失败伴随而来的是另外一个框架的应运而生.他就是至今也比较流行的Hibe ...
- 框架和事务 非常 有用 hibernate和mybatis区别
1****第一章 Hibernate与MyBatis 章 开发对比 开发学习 Hibernate的真正掌握要比Mybatis来得难些.Mybatis框架相对简单很容易上手,但也相对简陋些.个人觉得要用 ...
- Mybatis框架中实现双向一对多关系映射
学习过Hibernate框架的伙伴们很容易就能简单的配置各种映射关系(Hibernate框架的映射关系在我的blogs中也有详细的讲解),但是在Mybatis框架中我们又如何去实现 一对多的关系映射呢 ...
- 初识Mybatis框架,实现增删改查等操作(动态拼接和动态修改)
此第一次接触Mybatis框架确实是有点不适应,特别是刚从Hibernate框架转转型过来,那么为什么要使用Mybatis框架,Mybatis框架和Hibernate框架又有什么异同呢? 这个问题在我 ...
- JAVA面试中问及HIBERNATE与 MYBATIS的对比,在这里做一下总结
我是一名java开发人员,hibernate以及mybatis都有过学习,在java面试中也被提及问道过,在项目实践中也应用过,现在对hibernate和mybatis做一下对比,便于大家更好的理解和 ...
- hibernate 和 myBatis 比较
Hibernate与 MyBatis的比较 第一章 Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jbos ...
随机推荐
- git (unable to update local ref )
https://stackoverflow.com/questions/2998832/git-pull-fails-unable-to-resolve-reference-unable-to-upd ...
- 安装altium designer的破解问题
无法启动此程序,因为计算机中丢失MFC71.DLL.尝试重装安装该程序 百度下搜索下载MFC71.DLL,解压后复制到c:windows/system32/下,在开始-运行下输入regsvr32 MF ...
- C. RMQ with Shifts
C. RMQ with Shifts Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 131072KB 64-bit intege ...
- iOS 3D UI(3D翻转)
demo链接:http://pan.baidu.com/s/1eQVPj0m 先写个demo
- Python GUI 之 Treeview 学习
例子1 from tkinter import *import tkinter.ttk as ttk win = Tk()win.title("Treeview 学习") col ...
- [POJ2778]DNA Sequence(AC自动机 + DP + 矩阵优化)
传送门 AC自动机加DP就不说了 注意到 m <= 10,所以模式串很少. 而 n 很大就需要 log 的算法,很容易想到矩阵. 但是该怎么构建? 还是矩阵 A(i,j) = ∑A(i,k) * ...
- leetcode 94 中序遍历模板
/**递归的写法 * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * Tre ...
- MyBatis的参数,不能传入null
今天在调试的过程中发现一个bug,把传入的参数写到查询分析器中执行没有问题,但是在程序中执行就报错:org.springframework.jdbc.UncategorizedSQLException ...
- CF 2018 Battle of Brains GYM 102062 F
https://codeforces.com/gym/102062/attachments/download/8213/2018-battle-of-brains-en.pdf https://cod ...
- BZOJ 2957 楼房重建 (线段树)
题目链接 楼房重建 解题思路:我们可以把楼房的最高点的斜率计算出来.那么问题就转化成了实时查询x的个数,满足数列x的左边没有大于等于x的数. 我们可以用线段树维护 设t[i]为如果只看这个区间,可以 ...