1 join
a 为相关联的实体或集合指定一个别名
select mate
from Cat as cat
inner join cat.mate as mate
==
select cat.mate from Cat cat
b 外连接只能由于在映射中有配置关联表的类
select mate
from Cat as cat
left join cat.mate as mate
有一点要注意,使用外连接select不能省,否则将会返回一个对象数组。
2 fetch
要和join一起使用
fetch可以使延迟加载的属性立即加载
from TestUser t join fetch t.testEnterprise where t.id = 4
fetch不要和iterate(),setMaxResults(),setFirstResult()一起使用
因为使用了fecth后真实查询的结果集不仅仅只是from后面的表的字段
3 select的数据组织
a 存放在 Object[]队列
select mother, offspr, mate.name
from DomesticCat as mother
inner join mother.mate as mate
left outer join mother.kittens as offspr
b 存放在一个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
c 存放在一个实际的类型安全的Java对象
select new Family(mother, mate, offspr)
from DomesticCat as mother
join mother.mate as mate
left join mother.kittens as offspr
d 存放在一个Map对象
select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n )
from Cat cat
4 隐藏属性
一个“任意”类型有两个特殊的属性id和class
from AuditLog log, Payment payment
where log.item.class = 'Payment' and log.item.id = payment.id
5 多态查询
from java.lang.Object o
或
from domain.AbstractTestUser
这里注意除了映射过的表实体类型,其他的都要使用类全名
6 特殊的函数
HQL index() 函数,作用于join的有序集合的别名。
HQL函数,把集合作为参数:size(), minelement(), maxelement(), minindex(), maxindex(),还有特别的elements() 和indices函数,可以与
数量词加以限定:some, all, exists, any, in。
a 为相关联的实体或集合指定一个别名
select mate
from Cat as cat
inner join cat.mate as mate
==
select cat.mate from Cat cat
b 外连接只能由于在映射中有配置关联表的类
select mate
from Cat as cat
left join cat.mate as mate
有一点要注意,使用外连接select不能省,否则将会返回一个对象数组。
2 fetch
要和join一起使用
fetch可以使延迟加载的属性立即加载
from TestUser t join fetch t.testEnterprise where t.id = 4
fetch不要和iterate(),setMaxResults(),setFirstResult()一起使用
因为使用了fecth后真实查询的结果集不仅仅只是from后面的表的字段
3 select的数据组织
a 存放在 Object[]队列
select mother, offspr, mate.name
from DomesticCat as mother
inner join mother.mate as mate
left outer join mother.kittens as offspr
b 存放在一个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
c 存放在一个实际的类型安全的Java对象
select new Family(mother, mate, offspr)
from DomesticCat as mother
join mother.mate as mate
left join mother.kittens as offspr
d 存放在一个Map对象
select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n )
from Cat cat
4 隐藏属性
一个“任意”类型有两个特殊的属性id和class
from AuditLog log, Payment payment
where log.item.class = 'Payment' and log.item.id = payment.id
5 多态查询
from java.lang.Object o
或
from domain.AbstractTestUser
这里注意除了映射过的表实体类型,其他的都要使用类全名
6 特殊的函数
HQL index() 函数,作用于join的有序集合的别名。
HQL函数,把集合作为参数:size(), minelement(), maxelement(), minindex(), maxindex(),还有特别的elements() 和indices函数,可以与
数量词加以限定:some, all, exists, any, in。