首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

hibernate的查询-HQL查询

2012-07-04 
hibernate的查询--HQL查询前面已对hibernate常用的关系映射做了总结,下面对hibernate常用的HQL查询作一下

hibernate的查询--HQL查询
前面已对hibernate常用的关系映射做了总结,下面对hibernate常用的HQL查询作一下总结:

1.from子句
说到HQL语句,from子句是最简单的了,例如 from Employee(或:select e from Employee e),表示返回Employee类的所有实例。
例如:


         在查询多个属性时,把字段封装在一个对象中往往比使用对象数组更方便。下面 的程序将多个属性的查询结果进行了实例化:

但是要正确运行上面的程序,除了需要在Employee类中保留一个没参的构造函数外,还需加入一个如下带参数的构造函数:

7.hibernate中常用的表达式:

在where子句中允许使用的表达式包括大多数你可以在SQL使用的表达式种类:
?数学运算符+, -, *, /
?二进制比较运算符=, >=, <=, <>, !=, like
?逻辑运算符and, or, not
?in, not in, between, is null, is not null, is empty, is not empty, member of and not member of
?"简单的" case, case ... when ... then ... else ... end,和 "搜索" case, case when ... then ... else ... end
?字符串连接符...||... or concat(...,...)
?current_date(), current_time(), current_timestamp()
?second(...), minute(...), hour(...), day(...), month(...), year(...),
?SQL标量函数:例如upper()和lower()

如果子查询返回多条记录,可以用以下的关键字来量化:
all:表示所有的记录。
any:表示所有记录中的任意一条
some:与any用法相同。
in:与any等价。
exists:表示子查询至少要返回一条记录。

热点排行