posts - 167,  comments - 30,  trackbacks - 0
               摘要:   閱讀全文
          posted @ 2017-09-04 16:33 David1228 閱讀(308) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-08-02 11:41 David1228 閱讀(324) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-07-24 19:10 David1228 閱讀(11394) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-07-19 18:10 David1228 閱讀(3435) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-06-06 23:10 David1228 閱讀(293) | 評論 (0)編輯 收藏
          Netty客戶端與服務端通信
          posted @ 2017-06-06 23:09 David1228 閱讀(246) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-05-30 19:26 David1228 閱讀(3288) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-05-30 19:25 David1228 閱讀(1256) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-12-22 23:01 David1228 閱讀(4618) | 評論 (2)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-11-04 23:44 David1228 閱讀(2299) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-07-28 17:57 David1228 閱讀(402) | 評論 (0)編輯 收藏
               摘要: JVM調優總結 + jstat 分析jstat -gccause pid 1 每格1毫秒輸出結果jstat -gccause pid 2000 每格2秒輸出結果不斷的在屏幕打印出結果  S0     S1     E     &n...  閱讀全文
          posted @ 2016-01-03 23:26 David1228 閱讀(3000) | 評論 (2)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-12-27 16:49 David1228 閱讀(1092) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-10-31 12:37 David1228 閱讀(671) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-10-30 20:20 David1228 閱讀(2881) | 評論 (0)編輯 收藏
          轉載文章:http://www.qixing318.com/article/by-lua-adhesive-nginx-ecological-environment.html
          posted @ 2015-09-08 13:22 David1228 閱讀(513) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-09-08 09:34 David1228| 編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-07-29 13:48 David1228 閱讀(5556) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2014-12-03 23:56 David1228 閱讀(28341) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-11-19 11:48 David1228 閱讀(23747) | 評論 (1)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-11-18 18:01 David1228 閱讀(2904) | 評論 (4)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-10-31 17:32 David1228 閱讀(706) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-10-14 09:50 David1228 閱讀(21758) | 評論 (6)編輯 收藏
          Hibernate不支持left join帶on的條件查詢。
          解決辦法:使用原生SQL或者使用HQL方式需要修改hbm文件(如果項目中大部分不適用級聯配置情況下)
          需求是查詢網絡信息,網絡信息中關聯了分區、網絡IP(1個網絡--N個網絡IP),網橋信息.
          HQL:
          public void queryVnets(Page page) {
                  StringBuffer hql = new StringBuffer();
                  hql.append("select new Map(vn.id as id, vn.vnName as vnName, b.name as vnType, ");
                  hql.append("vn.vnIptype as vnIptype, vn.vnIp as vnIp,vn.vnNat as vnNat, vn.vnFlag as vnFlag, ");
                  hql.append("vn.vnetFlag as vnetFlag, (case when sum(vmvn.state)='0' then 0 else 1 endas vnState, ");
                  hql.append("vn.useType as useType, vn.createTime as createTime, ");
                  hql .append("zone.oneName as oneName, zone.oneHypervisor as oneHypervisor, zone.oneSeq as oneSeq) ");
                  hql.append("from VnetTable vn, ZoneTable zone, BridgeTable b ");
                  hql.append("left join fetch vn.VnTables vmvn where zone.id = vn.zoneId and vn.vnType = b.id ");

                  ... ...
                  hql.append(" group by vn.id");
                  if (vnState != null && !"".equals(vnState)) {
                      if ("0".equals(vnState)) {
                          hql.append(" having sum(vmvn.state)=0");
                      } else if ("1".equals(vnState)) {
                          hql.append(" having sum(vmvn.state)!=0");
                      }
                  }
              }

          hbm配置文件:
          <?xml version="1.0" encoding="utf-8"?>
          <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
          <!-- 
              Mapping file autogenerated by MyEclipse Persistence Tools
          -->
          <hibernate-mapping>
              <class name="com.base.mapping.VnetTable" table="vnet_table" >
                  <id name="id" type="java.lang.String">
                      <column name="ID" length="32" />
                      <generator class="uuid.hex" />
                  </id>
                  <property name="vnId" type="java.lang.Long">
                      <column name="VN_ID">
                          <comment>創建虛擬網絡時得到的ID</comment>
                      </column>
                  </property>
                   ...
                  <property name="zoneId" type="java.lang.String">
                      <column name="ZONE_ID" length="32">
                          <comment>分區ID</comment>
                      </column>
                  </property>
                  <property name="vlanId" type="java.lang.Integer">
                      <column name="VLAN_ID">
                          <comment>VLAN_ID</comment>
                      </column>
                  </property>
                  <set name="vnTables" lazy="false" order-by="id asc" inverse="false" fetch="join" cascade="all">
                      <key column="VN_NID"/>
                      <one-to-many class="com.base.mapping.VnTable"/>
                  </set>
              </class>
          </hibernate-mapping>

          理解inverse和cascade,可以參考:http://blog.csdn.net/wkcgy/article/details/6271321
          總結: 
          <one-to-many>中,建議inverse=”true”,由“many”方來進行關聯關系的維護 
          <many-to-many>中,只設置其中一方inverse=”false”,或雙方都不設置 
          Cascade,通常情況下都不會使用。特別是刪除,一定要慎重。
          操作建議 
            一般對many-to-one和many-to-many不設置級聯,這要看業務邏輯的需要;對one-to-one和one-to-many設置級聯。
            many-to-many關聯關系中,一端設置inverse=”false”,另一端設置為inverse=”true”。在one-to-many關聯關系中,設置inverse=”true”,由多端來維護關系表










          posted @ 2013-09-12 11:57 David1228 閱讀(16687) | 評論 (2)編輯 收藏
          -- 以下兩個查詢效率相當,查詢時間均為0.0xx秒,~ 但是Hibernate HQL不支持from后面接子查詢,可以直接使用SQL方式解決,ibatis當然可以用了。
          SELECT count(*from (
          SELECT sum(t2.STATE) as vnSum, t1.ID FROM
          vnetinfo_table t1, vm_vn_table t2 
          where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t where t.vnSum = 0;

          SELECT count(*) FROM vnetinfo_table v ,(
          SELECT sum(t2.STATE) as vnSum, t1.ID as idd FROM
          vnetinfo_table t1, vm_vn_table t2 
          where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t
          where v.ID = t.idd and t.vnSum = 0;

          -- 查詢效率太低了,查詢時間均為0.5xx秒左右。要比以上兩個SQL耗時很多倍。~ Hibernate支持在where后用子查詢作為查詢條件。
          SELECT count(*) FROM vnetinfo_table v WHERE v.id in 
          (SELECT CASE WHEN SUM(t2.STATE)=0 THEN t1.ID ELSE '' END
          FROM vnetinfo_table t1, vm_vn_table t2 
          where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID);

          -- 使用join方式替換in 查詢時間均為0.09x秒左右。明顯提高了效率,但是Hibernate HQL任然不支持在這種聯合子查詢方式。
          SELECT count(*) FROM vnetinfo_table v INNER JOIN (SELECT CASE WHEN SUM(t2.STATE)=0 THEN t1.ID ELSE '' END as idd
          FROM vnetinfo_table t1, vm_vn_table t2 
          WHERE t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t ON v.ID = t.idd and t.idd IS not NULL;

          附:Mysql中關于Exists用法的介紹請參見:http://www.nowamagic.net/librarys/veda/detail/639
          posted @ 2013-08-21 13:47 David1228 閱讀(3759) | 評論 (2)編輯 收藏

          <2013年8月>
          28293031123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          Java

          Linux知識相關

          Spring相關

          云計算/Linux/虛擬化技術/

          友情博客

          多線程并發編程

          開源技術

          持久層技術相關

          搜索

          •  

          積分與排名

          • 積分 - 358865
          • 排名 - 154

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 阿拉善盟| 海门市| 盖州市| 芦溪县| 徐州市| 周口市| 临桂县| 界首市| 池州市| 屯留县| 安西县| 蓬溪县| 汾阳市| 安平县| 黔西县| 韶关市| 锡林郭勒盟| 和平区| 鹤壁市| 富阳市| 塘沽区| 天台县| 柞水县| 兖州市| 米林县| 台中市| 东乌珠穆沁旗| 巴中市| 贡觉县| 延安市| 宽甸| 富蕴县| 松潘县| 灌阳县| 通许县| 通城县| 准格尔旗| 嘉善县| 霸州市| 宣汉县| 万安县|