Rising Sun

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            148 隨筆 :: 0 文章 :: 22 評論 :: 0 Trackbacks

          1問題: hibernate不用外鍵作查詢:
          1.1最終解辦法: 利用hibernate 的視圖功能
          Hibernate3增加了視圖功能

          1. 定義hbm

              <class name="Customer" table="customer">        
                  
          <id name="id" unsaved-value="0" column="id">
                      
          <generator class="hilo"/>
                  
          </id>        
                  
          <property name="name"  not-null="true"/>        
              
          </class>
              
              
          <class name="Supplier" table="supplier">        
                  
          <id name="id" unsaved-value="0" column="id">
                      
          <generator class="hilo"/>
                  
          </id>
                  
          <property name="name" not-null="true"/>            
              
          </class>
              
              
          <class name="All" mutable="false">    
                  <subselect>
                      select id, name from customer
                      union 
                      select id, name from supplier
                  
          </subselect>
                  
                  
          <synchronize table="customer"/>
                  
          <synchronize table="supplier"/>
                  
                  
          <id name="id" unsaved-value="0" column="id">
                      
          <generator class="hilo"/>
                  
          </id>        
                  
          <property name="name"/>        
              
          </class>


          2. 定義POJO

          pulic class Customer {
              
          public Integer id;
              
          public String name;
          }


          pulic 
          class Supplier {
              
          public Integer id;
              
          public String name;
          }


          pulic 
          class All {
              
          public Integer id;
              
          public String name;
          }


          3. 查詢

          List all = session.createQuery("from All").list();
          注意:黃色地區


          解決辦法二

          1.2 在數據表里 建視圖, 把視圖當表操作.

          解決辦法三
          1.3 設外鍵=沒說,,哈哈

          總結,不用外鍵.為了建表方便.  

          To Be Continued……



          posted on 2007-09-04 11:02 brock 閱讀(315) 評論(0)  編輯  收藏 所屬分類: hibernate+struts+spring
          主站蜘蛛池模板: 顺义区| 肥西县| 淮南市| 千阳县| 揭阳市| 文水县| 华安县| 乡城县| 潼关县| 赣榆县| 衡水市| 鹤岗市| 溧水县| 满城县| 霸州市| 科尔| 高阳县| 葫芦岛市| 齐齐哈尔市| 雷州市| 恩施市| 赣榆县| 青海省| 邛崃市| 安图县| 错那县| 嘉荫县| 忻城县| 高碑店市| 阆中市| 宁武县| 武冈市| 化隆| 蒙城县| 监利县| 格尔木市| 东宁县| 宿迁市| 长岭县| 乐亭县| 页游|