hibernate createSQLQuery与connection效率

环境: 双核  2G内存

DB: mysql  hibernate+spring

 

hibernate执行sql语句的两种方式:

 

第一种方式:hibernate createSQLQuery里面可以传入传统的sql语句进行查询,它的返回值为一个数组,

 

第二种方式:hibernate session.connection得到的是一个java.sql.Connection对象,以下的操作就和jdbc一样的操作 。

 

我用以上两种方式查询1条记录:

String sql = "select m.id,m.m_recordState,m.m_number,m.m_name,m.m_typeid,m.m_spec,m.m_model," +"m.m_color,m.m_weight,m.m_weightunit,m.m_volume,m.m_volumeunit,m.m_height,m.m_width,m.m_oneortwo," + "m.m_state,m.m_recordMaker,m.m_recordDate from t_Material m join t_PurchaseList l on " +
 "m.id=l.p_materiaId join t_PurchaseOrder p on p.id=l.parentid " +
 "where p.o_vendor='0011' and m.m_state=1 and m.m_recordState=1";

 

第一种用时 62毫秒 第二种用时47毫秒(我用同事的机器测试第一种方式竟然用了100多毫秒,两种方式用时相差一半多)

 

我换了sql语句

String sql = "select m.* from t_Material m join t_PurchaseList l on " +
                "m.id=l.p_materiaId join t_PurchaseOrder p on p.id=l.parentid " +
               "where p.o_vendor='0011' and m.m_state=1 and m.m_recordState=1";

第一种用时 78毫秒 第二种用时47毫秒

 

所以用hibernate执行sq1语句的两种方式差别:

 

1: sqlquery :hibernate对其返回值进行了封装相差 connection: hibernate没有对其进行任何的封装  两种方式用时相差很大,(根据机器配置不同,则相差不同)总之,相差近一半.

 

2: sql语句: 采用select * 和分别列出每个列 对connection来说没有影响,对sqlquery来说也会有相差

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值