HQL: select子句

查询语句可以返回值为任何类型的属性或对象,包括返回类型为某种组件(Component)的属性:
select cust.name.firstName from Customer as cust
select cat.mate from Cat cat

查询语句可以返回多个对象和(或)属性,存放在 Object[] 队列中:
select mother , offspr , mate.name
from DomesticCat as mother
    inner join mother.mate as mate
    left join mother.kittens as offspr

或存放在一个List 对象中:
select new list (mother, offspr, mate.name)
from DomesticCat as mother
    inner join mother.mate as mate
    left outer join mother.kittens as offspr

 

也可能直接返回一个实际的类型安全的Java对象(假设类Family 有一个合适的构造函数 ):
select new Family( mother, mate, offspr)
from DomesticCat as mother
    join mother.mate as mate
    left join mother.kittens as offspr

也可以使用关键字as 给“被选择了的表达式”指派别名:
select max(bodyWeight) as max , min(bodyWeight) as min , count(*) as n
from Cat cat
这种做法在与子句select new map 一起使用时最有用:
select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n )
from Cat cat

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值