日期:2014-05-16  浏览次数:20501 次

我对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_.CO