Hibernate学习笔记9
学习课程:
|
简单属性查询 |
SimplePropertyQueryTest |
|
实体对象查询 |
SimleObjectQueryTest |
|
条件查询 |
ConditionQueryTest |
|
原生SQL查询 |
ConditionQueryTest |
|
外置命名查询 |
NameQueryTest |
|
查询过滤器 |
FilterQueryTest |
|
分页查询 |
PageQueryTest |
|
对象导航查询 |
ObjectNavigationQueryTest |
|
连接查询 |
JoinQueryTest |
|
统计查询 |
StatisticsQueryTest |
|
DML查询 |
DMLQueryTest |
HQL简介
|
数据查询与检索是Hibernate中的一个亮点,相对其他ORM实现而言,Hibernate 提供了灵活多样的查询机制。 HQL(Hibernate Query Language):它是完全面向对象的查询语句,查询功能非常 强大,具备多态,关联等操作, HQL用面向对象的方式生成SQL *以类和属性来代替表和数据列 *支持多态 *支持各种关联 *减少了SQL的冗余 HQL支持所有的关系数据库操作 *连接(joins,包括Inner/Oouter/full joins) ,笛卡尔积(cartesion products) *投影(projection) *聚合(Aggregation,max,avg)和分组(group) *排序(Ordering) *子查询(Subqueries) *SQL函数(SQL function calls) HQL查询对象,不会直接查表,关键字不区分大小写,但是属性和类名区分大小写 中立的一套语言
准备工作: 在Student中加入createTime,对时间进行查询 |
1.简单属性查询
|
testQuery1
|
| |
|
testQuery2
|
| |
|
testQuery3
|
| |
|
testQuery4
|
| |
|
testQuery5
|
|
2.实体对象查询
|
testQuery1
|
| ||
|
testQuery2
|
| ||
|
testQuery3
|
| ||
|
testQuery4
|
| ||
|
testQuery5
|
| ||
|
testQuery6
|
| ||
|
testQuery7
|
| ||
|
testQuery8
|
|
3.条件查询
|
testQuery1
|
| |
|
testQuery2
|
| |
|
testQuery3
|
| |
|
testQuery4
|
| |
|
testQuery5
|
| |
|
testQuery6
|
| |
|
testQuery7
|
不会使用,教程中使用的是MySQL数据库,本机的是SQL Server 2000,还有我的数据库知识欠缺 | |
|
testQuery8
|
| |
|
testQuery9
|
|
4.外置命名查询
|
将HQL放到外置文件中,降低耦合度 |
|
|
5.查询过滤器
|
步骤:
作用域:
配置文件,加入标签
在class标签内加入
调用方法
|
6.分页查询【重要】
|
7.对象导航查询,在HQL中采用 "."进行导航,进行查询【重要】
|
8.连接查询【重要】
|
连接分为: 内连 外连(左连接,右连接) | |||
|
testQuery1
|
| ||
|
testQuery2
|
| ||
|
testQuery3
|
| ||
9.统计查询【重要】
|
testQuery1
|
| |
|
testQuery2
|
|
10.DML风格的操作
|
//批量更新 //建议少用因为和缓存不同步 |
|
|
本文介绍Hibernate中的多种查询方式,包括简单属性查询、实体对象查询、条件查询等,并详细讲解了每种查询方式的具体实现方法。
852





