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

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

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

    Java學(xué)習(xí)

    java,spring,structs,hibernate,jsf,ireport,jfreechart,jasperreport,tomcat,jboss -----本博客已經(jīng)搬家了,新的地址是 http://www.javaly.cn 如果有對(duì)文章有任何疑問(wèn)或者有任何不懂的地方,歡迎到www.javaly.cn (Java樂(lè)園)指出,我會(huì)盡力幫助解決。一起進(jìn)步

     

    HQL語(yǔ)句的語(yǔ)法

    1.from子句
    from Person
    表明從Person持久化類(lèi)中選出全部的實(shí)例。
    推薦:from Person as p

    2.select子句
    select p.name from Person as p
    select p.name.firstName from Person as p
    select new list(p.name, p.address) from Person as p
    select new ClassTest(p.name, p.address) from Person as p (有前提)
    select p.name as personName from Person as p
    select new map(p.name as personName) from Person as p (與new map()結(jié)合更普遍)

    3.聚集函數(shù)
    avg,count,max,min,sum
    select count(*) from Person
    select max(p.age) from Person as p
    select p.name || "" || p.address from Person as p

    4.多態(tài)查詢(xún)
    from Person as p
    from java.lang.Object o
    from Named as n

    5.where子句
    from Person where name like "tom%"
    from Person as p where p.name like "tom%"
    from Cat cat where cat.mate.name like "kit%"
    select * from cat_table as table1 cat_table as table2 where table1.mate =
    table2.id and table1.name like "kit%"
    from Foo foo where foo.bar.baz.customer.address.city like "fuzhou%"
    from Cat cat, Cat rival where cat.mate = rival.mate
    select cat, mate
    from Cat cat, Cat mate
    where cat.mate = mate
    from Cat as cat where cat.id = 123
    from Cat as cat where cat.mate.id = 69
    from Person as person
    where person.id.country = 'AU'
    and person.id.medicareNumber = 123456
    from Account as account
    where account.owner.id.country = 'AU'
    and account.owner.id.medicareNumber = 123456
    from Cat cat where cat.class = DomesticCat
    from Account as a where a.person.name.firstName like "dd%" // 正確
    from Account as a where a.person.name like "dd%" // 錯(cuò)誤

    6.表達(dá)式
    from DomesticCat cat where cat.name between 'A' and 'B'
    from DomesticCat cat where cat.name in ('Foo', 'Bar', 'Baz')
    from DomesticCat cat where cat.name not between 'A' and 'B'
    from DomesticCat cat where cat.name not in ('Foo', 'Bar', 'Baz')
    from DomesticCat cat where cat.name is null
    from Person as p where p.address is not null
    true 1, false 0
    from Cat cat where cat.alive = true
    from Cat cat where cat.kittens.size > 0
    from Cat cat where size(cat.kittens) > 0
    from Calendar cal where maxelement(cal.holidays) > current date
    from Order order where maxindex(order.items) > 100
    from Order order where minelement(order.items) > 10000
    //操作集合元素
    select mother from Cat as mother, Cat as kit
    where kit in elements(foo.kittens)
    //p的name屬性等于集合中某個(gè)元素的name屬性
    select p from NameList list, Person p
    where p.name = some elements(list.names)
    //操作集合元素
    from Cat cat where exists elements(cat.kittens)
    from Player p where 3 > all elements(p.scores)
    from Show show where 'fizard' in indices(show.acts)
    //items是有序集合屬性,items[0]代表第一個(gè)元素
    from Order order where order.items[0].id = 1234
    //holidays是map集合屬性,holidays[national day]是代表其中第一個(gè)元素
    select person from Person person, Calendar calendar
    where calendar.holidays['national day'] = person.birthDay
    and person.nationality.calendar = calendar
    //下面同時(shí)使用list集合和map集合屬性
    select item from Item item, Order order
    where order.items[order.deliveredItemIndices[0]] = item and order.id = 11
    select item from Item item, Order order
    where order.items[maxindex(order.items)] = item and order.id = 11

    select item from Item item, Order order
    where order.items[size(order.items) - 1] = item

    select cust
    from Product prod,
    Store store
    inner join store.customers cust
    where prod.name = 'widget'
    and store.location.name in ['Melbourne', 'Sydney']
    and prod = all elements(cust.currentOrder.lineItems)

    SELECT cust.name, cust.address, cust.phone, cust.id, cust.current_order
    FROM customers cust,
    stores store,
    locations loc,
    store_customers sc,
    product prod
    WHERE prod.name = 'widget'
    AND store.loc_id = loc.id
    AND loc.name IN ('Melbourne', 'Sydney')
    AND sc.store_id = store.id
    AND sc.cust_id = cust.id
    AND prod.id = ALL(
    SELECT item.prod_id
    FROM line_items item, orders o
    WHERE item.order_id = o.id
    AND cust.current_order = o.id
    )

    7.order by子句
    from Person as p
    order by p.name, p.age
    from Person as p
    order by p.name asc, p.age desc

    8.group by子句
    select cat.color, sum(cat.weight), count(cat)
    from Cat cat
    group by cat.color
    //select后出現(xiàn)的id處出現(xiàn)在group by之后,而name屬性則出現(xiàn)在聚集函數(shù)中
    select foo.id, avg(name), max(name)
    from Foo foo join foo.names name
    group by foo.id

    select cat.color, sum(cat.weight), count(cat)
    from Cat cat
    group by cat.color
    having cat.color in (eg.Color.TABBY, eg.Color.BLACK)

    select cat
    from Cat cat
    join cat.kittens kitten
    group by cat
    having avg(kitten.weight) > 100
    order by count(kitten) asc, sum(kitten.weight) desc

    9.子查詢(xún)
    from Cat as fatcat
    where fatcat.weight > (select avg(cat.weight) from DomesticCat cat)

    from Cat as cat
    where not (cat.name, cat.color) in (
    select cat.name, cat.color from DomesticCat cat
    )

    10.fetch關(guān)鍵字
    from Person as p join p.scores

    from Document fetch all properties order by name
    from Document doc fetch all properties where lower(doc.name) like '%cat%'

     11.執(zhí)行hql
              String hql ="update ContentReply contentReply set active = false where contentReply.id =:replyId";
            getSession().createQuery(hql).setString("replyId", replyId).executeUpdate();


    posted on 2008-10-20 15:39 找個(gè)美女做老婆 閱讀(991) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    統(tǒng)計(jì)

    公告

    本blog已經(jīng)搬到新家了, 新家:www.javaly.cn
     http://www.javaly.cn

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 污视频网站在线免费看| 国产午夜亚洲精品不卡免下载 | 亚洲国产精品网站在线播放| 亚洲色婷婷综合开心网| 老司机午夜在线视频免费观| 国产精品久久免费视频| 激情婷婷成人亚洲综合| 亚洲成av人片天堂网老年人| 手机永久免费的AV在线电影网| 国产一级理论免费版| 一个人免费观看视频在线中文 | 成人a毛片免费视频观看| 国产午夜亚洲不卡| 在线看片免费人成视频福利| 亚洲美女又黄又爽在线观看| 野花香高清视频在线观看免费| 亚洲AV成人精品网站在线播放| 99re6在线精品视频免费播放 | 亚洲精品av无码喷奶水糖心| 国产自产拍精品视频免费看| 男人j进女人p免费视频| 国产亚洲综合一区柠檬导航| 中文字幕亚洲免费无线观看日本 | 亚洲高清在线mv| 动漫黄网站免费永久在线观看| 亚洲中文字幕久久无码| 亚洲国产成人乱码精品女人久久久不卡 | 成人免费视频国产| 国产精品青草视频免费播放| 亚洲AV人无码激艳猛片| 最近免费中文字幕大全| 无人视频在线观看免费播放影院| 亚洲色精品aⅴ一区区三区| 亚洲电影免费观看| 国产亚洲精品国产福利在线观看| 亚洲女久久久噜噜噜熟女| 69式互添免费视频| 免费无遮挡无码视频在线观看 | 四虎影视永久免费观看| a毛片在线免费观看| 国产精品亚洲精品|