<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 495,comments - 227,trackbacks - 0
    +++在映射文件中定義命名查詢
    <class .. >
    </class>
    <query name="findCustomersByName"><![CDATA[
        from Customer c where c.name like :name
    ]]></query>
    語句:Query q=session.getNamedQuery("findCustomersByName");
         q.setString("name",name);
         List result=query.list();
    ++++ HQL Vs QBC 檢索方式

    比較運算
     . 檢索年齡大于18的Customer
         HQL  session.createQuery("from Customer cwhere c.age>18");
         QBC  Criteria criteria=session.createCriteria(Customer.class);
              criteria.add(Expression.gt("age",18));
    2 . 檢索年齡不等于 18的
        HQL session.createQuery("from Customer c where c.age<>18")
        QBC Criteria criteria =session.createCriteria(Customer.class);
            criteria.add(Expression.not(Expression.eq("age",new Integer(18))));
    3.  檢索姓名為空的Customer對象
       HQL  session.createQuery("from Customer c where c.name is null");
       QBC  Criteria criteria =session.createCriteria(Customer.class);
            criteria.add(Expression.isNull("name"));
    4. 檢索不屬于任何客戶的訂單
       HQL  session.createQuery("from Order o where o.customer is null");
       QBC  Criteria criteria =session.createCriteria(Order.class);
            criteria.add(Expression.isNull("customer"));
    5. HQL  Query q=session.createQuery("from Customer c where lower(c.name)='tom'");
            Query q=session.createQuery("from Customer c where upper(c.name)='TOM'");
       QBC  Criteria criteria =session.createCriteria(Customer.class);
            criteria.add(Expression.eq("name","tom").ignoreCase());
    范圍運算
    1. 檢查姓名為 Tom,Mike 或者Jack 的 Customer對象
        HQL session.createQuery("from Customer c where c.name in('Tom','Mike','Jack')");
        QBC Criteria criteria=session.createCriteria(Customer.class);
             String names[]={"Tom","Mike","Jack"};
             criteria.add(Expression.in("name",names));
    2. 檢查年齡在 18 到  25之間的Customer對象
       HQL session.createQuery("from Customer c where c.age between 18 and 25");
       QBC Criteria criteria=session.createCriteria(Customer.class);
           criteria.add(Expression.between("age",new Integer(18),newInteger(25)))
    3. 檢索年齡不在 18到  25之間的Customer對象;
       HQL session.createQuery("from Customer c where c.age not between 18 and 25");
       QBC Criteria criteria=session.createCriteria(Customer.class);
           criteria.add(Expression.not(Expression.between("age",new Integer(18),newInteger(25))))
    字符串模式匹配
    1. 檢索姓名以 "T"開頭的Customer對象
         HQL  session.createQuery("from Customer cwhere c.name like 'T%'");
         QBC  Criteria criteria=session.createCriteria(Customer.class);
              criteria.add(Expression.like("name","T%"));
               %表示  任意個字符
               _表示  一個字符
              Or
             criteria.add(Expression.like("name","T",MatchMode.START));
          MatchMode 類中有:
                           START    開頭
                           END      結尾
                           ANYWHERE 包含
                           EXACT    精確
    邏輯運算符
      Expression.and(Expression1,Expression2);
      Expression.or(Expression1,Expression2);
      
    連接查詢:::::
    1 . 映射文件中的配置
    lazy="true" 延遲加載
    fetch="select" 迫切加載
    2.
      2.1  迫切左外連接, HQL : from Customer c left join fetch c.orders o where c.name like 'T'");
                       QBC : criteria.setFetchMode("orders",FetchMode.EAGER); 迫切加載
         QBC 只支持 迫切左外連接,與內連接
      2.2  左外連接,    HQL : from Customer c left join c.orders where c.name like 'T%'
                        
      2.3 內連接     HQl :  from Customer c inner join c.orders o where c.name like 'T%'
              
      
    2.4 迫切內連接 ,  HQL:  from customer c inner join fetch c.orders o where c.name like 'T%'
    2.5 隱式內連接 , HQL :  from customer c where c.homeAddress.provice like '%hai'
    2.6 右外連接  ,   HQL :  from customer right outer join c.orders o where c.name like 'T%'

    報表查詢 :
       select new mypack.CustomerRow(c.id,c.name,o.orderNumber)
       from customer c join c.orders o
       where o.orderNumber like 'T%'

       distinct 關鍵字 消除重復關鍵字
       order by  asc||desc 排序
       group by 列    分組查詢
    posted on 2011-06-01 21:54 SIMONE 閱讀(938) 評論(0)  編輯  收藏 所屬分類: JAVA
    主站蜘蛛池模板: 日本中文一区二区三区亚洲| 免费女人高潮流视频在线观看| 亚洲自国产拍揄拍| 亚洲一区二区三区深夜天堂| 亚洲精品亚洲人成在线| 男女作爱免费网站| a级黄色毛片免费播放视频| 亚洲精品免费网站| 四虎成人精品在永久免费 | 一级毛片在线观看免费| 拍拍拍又黄又爽无挡视频免费| 免费人成在线观看播放国产| 亚洲av福利无码无一区二区| 亚洲欧美日韩中文无线码| 成人a视频片在线观看免费| 亚洲精品中文字幕无码蜜桃| 亚洲熟女精品中文字幕| 日韩免费观看一区| 大胆亚洲人体视频| 亚洲黄片手机免费观看| 成人免费视频88| 国产精品亚洲AV三区| 99热在线免费播放| 亚洲jjzzjjzz在线播放| 欧洲精品免费一区二区三区| 亚洲精品国产手机| 免费黄色电影在线观看| 亚洲精品网站在线观看不卡无广告 | 你懂的在线免费观看| 亚洲av午夜福利精品一区人妖| 亚洲欧洲av综合色无码| 免费a级毛片无码a∨性按摩| 99免费在线视频| 亚洲中文字幕久久精品无码2021| 日韩免费毛片视频| 亚洲国产区男人本色| 久久久久国产精品免费免费搜索 | 久久精品视频免费| 亚洲中文无码永久免| 亚洲午夜成人精品电影在线观看| 久久久久亚洲国产|