主要内容

1HQL概述

2SimpleQuery查询

3ScalarQuery查询

4.自定义查询

5.使用CallBack

 

一.HQL简单介绍

HQL全名是Hibernate Query Language,它是一种完全面向对象的查询语言。先来看一下HQL最基本的一些用法

1.From子句

使用HQL查询from Post

你也可以为Post起一个别名

使用HQL查询from Post as post

或者省略as

使用HQL查询from Post post

2.Select 子句

使用HQL查询select Name,Author from Blog

也可以使用elements函数来查询一个集合

使用HQL查询select elements(blog.Posts) from Blog blog

3.使用聚合函数

HQL中也可以使用一些聚合函数

使用HQL查询select count(*from Blog blog

 

使用HQL查询select count(elements(blog.Posts)) from Blog blog

HQL支持的聚合函数有

使用HQL查询avg(使用HQL查询), sum(使用HQL查询), min(使用HQL查询), max(使用HQL查询
使用HQL查询
使用HQL查询
count(*
使用HQL查询
使用HQL查询
count(使用HQL查询), count(distinct 使用HQL查询), count(all使用HQL查询)

4.Where子句

使用HQL查询from Blog blog where blog.Name = ‘Terry Lee’

 

使用HQL查询from Blog blog where blog.Name is not null

详细可以参考http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2021-12-09
  • 2021-12-01
猜你喜欢
  • 2021-10-27
  • 2021-07-22
  • 2022-01-31
相关资源
相似解决方案