posts - 167,  comments - 30,  trackbacks - 0
               摘要:   閱讀全文
          posted @ 2017-09-04 16:33 David1228 閱讀(313) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-08-02 11:41 David1228 閱讀(335) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-07-24 19:10 David1228 閱讀(11409) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-07-19 18:10 David1228 閱讀(3446) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-06-06 23:10 David1228 閱讀(298) | 評論 (0)編輯 收藏
          Netty客戶端與服務端通信
          posted @ 2017-06-06 23:09 David1228 閱讀(250) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-05-30 19:26 David1228 閱讀(3298) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-05-30 19:25 David1228 閱讀(1266) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-12-22 23:01 David1228 閱讀(4628) | 評論 (2)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-11-04 23:44 David1228 閱讀(2310) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-07-28 17:57 David1228 閱讀(406) | 評論 (0)編輯 收藏
               摘要: JVM調優總結 + jstat 分析jstat -gccause pid 1 每格1毫秒輸出結果jstat -gccause pid 2000 每格2秒輸出結果不斷的在屏幕打印出結果  S0     S1     E     &n...  閱讀全文
          posted @ 2016-01-03 23:26 David1228 閱讀(3005) | 評論 (2)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-12-27 16:49 David1228 閱讀(1099) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-10-31 12:37 David1228 閱讀(677) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-10-30 20:20 David1228 閱讀(2891) | 評論 (0)編輯 收藏
          轉載文章:http://www.qixing318.com/article/by-lua-adhesive-nginx-ecological-environment.html
          posted @ 2015-09-08 13:22 David1228 閱讀(520) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-09-08 09:34 David1228| 編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-07-29 13:48 David1228 閱讀(5563) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2014-12-03 23:56 David1228 閱讀(28352) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-11-19 11:48 David1228 閱讀(23759) | 評論 (1)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-11-18 18:01 David1228 閱讀(2912) | 評論 (4)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-10-31 17:32 David1228 閱讀(713) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-10-14 09:50 David1228 閱讀(21772) | 評論 (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 閱讀(16703) | 評論 (2)編輯 收藏

          <2013年9月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          Java

          Linux知識相關

          Spring相關

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

          友情博客

          多線程并發編程

          開源技術

          持久層技術相關

          搜索

          •  

          積分與排名

          • 積分 - 359875
          • 排名 - 154

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 内黄县| 古蔺县| 瑞金市| 凤山县| 桃园市| 石楼县| 漳州市| 苍山县| 远安县| 海盐县| 昌乐县| 福建省| 寿光市| 蒙自县| 锦屏县| 桂东县| 筠连县| 呼和浩特市| 绩溪县| 青海省| 通城县| 新巴尔虎左旗| 嘉善县| 乐山市| 宜章县| 香港 | 盐源县| 太仓市| 井陉县| 茂名市| 北川| 东至县| 巴青县| 温泉县| 丹阳市| 阜南县| 秭归县| 当阳市| 剑河县| 广汉市| 汉源县|