- 浏览: 1495095 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (523)
- JAVA (334)
- J2EE (18)
- JSP (21)
- JavaScript (14)
- it life (2)
- mobile develop (4)
- UBUNTU (14)
- Algorithm (14)
- DataBase (56)
- Browser/Server (1)
- linux (6)
- fedora (2)
- CSS (1)
- AjAX (3)
- HTML5 (1)
- EJB (1)
- osworkflow (2)
- Java face (5)
- spring (4)
- ICE (1)
- webService (2)
- MongoDB (1)
- JavaThread (4)
- JavaCollections (3)
- Hibernate (2)
- JavaMail (1)
- JavaBasic (1)
- Cache (1)
- https (4)
- DOM4J (1)
- JDOM (0)
- Mybatis (1)
- JUNIT (1)
- eclipse (1)
- easyMock (2)
最新评论
-
yadongliang:
...
自己认为的一些技术点 -
yadongliang:
每次看你头像都看的荷尔蒙分泌失调
WebService的两种方式SOAP和REST比较 (转) -
yadongliang:
hollo 写道一直有这种感觉,盲目的跟风,确实有一些人为了潮 ...
WebService的两种方式SOAP和REST比较 (转) -
welss:
博主,JNative怎么调用dll中的这种方法: int ...
JNative调用DLL -
Java_Antelope:
session.setAttribute和session.getAttribute(
HQL:Hibernate Query Language
HQL是完全面向对象的查询语言,因此可以支持继承和多态等特征。
HQL查询依赖于Query类,每个Query实例对应一个查询对象,使用HQL查询按
如下步骤进行:
(1)获取Hibernate Session对象;
(2)编写HQL语句;
(3)以HQL语句作为参数,调用Session的createQuery方法创建查询对象;
(4)如果HQL语句包含参数,调用Query的setXxx方法为参数赋值;
(5)调用Query对象的list等方法遍历查询结果。
查询示例:
1. public class HqlQuery
2. {
3. public static void main(String[] args) throws Exception {
4. HqlQuery mgr = new HqlQuery();
5. //调用查询方法
6. mgr.findPersons();
7. //调用第二个查询方法
8. mgr.findPersonByHappenDate();
9. HibernateUtil.sessionFactory.close();
10. }
11. //第一个查询方法
12. private void findPersons() {
13. //获得Hibernate Session
14. Session sess = HibernateUtil.currentSession();
15. //开始事务
16. Transaction tx = sess.beginTransaction();
17. //以HQL语句创建Query对象
18. //执行setString方法为HQL语句的参数赋值
19. //Query调用list方法访问查询的全部实例
20. List p1 = sess.createQuery("from Person p where o.myEvents.title = :
21. eventTitle").setString("eventTitle", "很普通事情").list();
22. //遍历查询的全部结果
23. for (Iterator pit = p1.iterator(); pit.haxNext(); )
24. {
25. Person p = (Person)pit.next();
26. System.out.println(p.getName());
27. }
28. //提交事务
29. tx.commit();
30. HibernateUtil.closeSession();
31. }
32. //第二个查询方法
33. private void findPersonByHappenDate() throws Exception {
34. Session sess = HibernateUtil.currentSession();
35. Transaction tx = sess.beginTransaction();
36. //解析出Date对象
37. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
38. Date start = sdf.parse("2007-11-27");
39. System.out.println("系统开始通过日期查找人" + start);
40. //通过Session的createQuery方法创建Query对象
41. //设置参数
42. //返回结果集
43. List pl = sess.createQuery(
44. "from Person p where p.myEvents.happenDate between :firstDate
45. and :endDate")
46. .setDate("firstDate", start)
47. .setDate("endDate", new Date())
48. .list();
49. //遍历结果集
50. for (Iterator pit = pl.iterator(); pit.hasNext(); )
51. {
52. Person p = (Person)pit.next();
53. System.out.println(p.getName());
54. }
55. tx.commit();
56. HibernateUtil.closeSession();
57. }
58. }
$下面介绍HQL语句的语法
1.from子句
1. from Person
表明从Person持久化类中选出全部的实例。
推荐:from Person as p
2.select子句
1. select p.name from Person as p
2. select p.name.firstName from Person as p
3. select new list(p.name, p.address) from Person as p
4. select new ClassTest(p.name, p.address) from Person as p (有前提)
5. select p.name as personName from Person as p
6. select new map(p.name as personName) from Person as p (与new map()结合更普遍)
3.聚集函数
1. avg,count,max,min,sum
2. select count(*) from Person
3. select max(p.age) from Person as p
4. select p.name || "" || p.address from Person as p
4.多态查询
1. from Person as p
2. from java.lang.Object o
3. from Named as n
5.where子句
1. from Person where name like "tom%"
2. from Person as p where p.name like "tom%"
3. from Cat cat where cat.mate.name like "kit%"
4. select * from cat_table as table1 cat_table as table2 where table1.mate =
5. table2.id and table1.name like "kit%"
6. from Foo foo where foo.bar.baz.customer.address.city like "fuzhou%"
7. from Cat cat, Cat rival where cat.mate = rival.mate
8. select cat, mate
9. from Cat cat, Cat mate
10. where cat.mate = mate
11. from Cat as cat where cat.id = 123
12. from Cat as cat where cat.mate.id = 69
13. from Person as person
14. where person.id.country = 'AU'
15. and person.id.medicareNumber = 123456
16. from Account as account
17. where account.owner.id.country = 'AU'
18. and account.owner.id.medicareNumber = 123456
19. from Cat cat where cat.class = DomesticCat
20. from Account as a where a.person.name.firstName like "dd%" // 正确
21. from Account as a where a.person.name like "dd%" // 错误
6.表达式
1. from DomesticCat cat where cat.name between 'A' and 'B'
2. from DomesticCat cat where cat.name in ('Foo', 'Bar', 'Baz')
3. from DomesticCat cat where cat.name not between 'A' and 'B'
4. from DomesticCat cat where cat.name not in ('Foo', 'Bar', 'Baz')
5. from DomesticCat cat where cat.name is null
6. from Person as p where p.address is not null
7. <property name="hibernate.query.substitutions">true 1, false 0</property>
8. from Cat cat where cat.alive = true
9. from Cat cat where cat.kittens.size > 0
10. from Cat cat where size(cat.kittens) > 0
11. from Calendar cal where maxelement(cal.holidays) > current date
12. from Order order where maxindex(order.items) > 100
13. from Order order where minelement(order.items) > 10000
14. //操作集合元素
15. select mother from Cat as mother, Cat as kit
16. where kit in elements(foo.kittens)
17. //p的name属性等于集合中某个元素的name属性
18. select p from NameList list, Person p
19. where p.name = some elements(list.names)
20. //操作集合元素
21. from Cat cat where exists elements(cat.kittens)
22. from Player p where 3 > all elements(p.scores)
23. from Show show where 'fizard' in indices(show.acts)
24. //items是有序集合属性,items[0]代表第一个元素
25. from Order order where order.items[0].id = 1234
26. //holidays是map集合属性,holidays[national day]是代表其中第一个元素
27. select person from Person person, Calendar calendar
28. where calendar.holidays['national day'] = person.birthDay
29. and person.nationality.calendar = calendar
30. //下面同时使用list集合和map集合属性
31. select item from Item item, Order order
32. where order.items[order.deliveredItemIndices[0]] = item and order.id = 11
33. select item from Item item, Order order
34. where order.items[maxindex(order.items)] = item and order.id = 11
35.
36. select item from Item item, Order order
37. where order.items[size(order.items) - 1] = item
38.
39. select cust
40. from Product prod,
41. Store store
42. inner join store.customers cust
43. where prod.name = 'widget'
44. and store.location.name in ['Melbourne', 'Sydney']
45. and prod = all elements(cust.currentOrder.lineItems)
46.
47. SELECT cust.name, cust.address, cust.phone, cust.id, cust.current_order
48. FROM customers cust,
49. stores store,
50. locations loc,
51. store_customers sc,
52. product prod
53. WHERE prod.name = 'widget'
54. AND store.loc_id = loc.id
55. AND loc.name IN ('Melbourne', 'Sydney')
56. AND sc.store_id = store.id
57. AND sc.cust_id = cust.id
58. AND prod.id = ALL(
59. SELECT item.prod_id
60. FROM line_items item, orders o
61. WHERE item.order_id = o.id
62. AND cust.current_order = o.id
63. )
7.order by子句
1. from Person as p
2. order by p.name, p.age
3. from Person as p
4. order by p.name asc, p.age desc
8.group by子句
1. select cat.color, sum(cat.weight), count(cat)
2. from Cat cat
3. group by cat.color
4. //select后出现的id处出现在group by之后,而name属性则出现在聚集函数中
5. select foo.id, avg(name), max(name)
6. from Foo foo join foo.names name
7. group by foo.id
8.
9. select cat.color, sum(cat.weight), count(cat)
10. from Cat cat
11. group by cat.color
12. having cat.color in (eg.Color.TABBY, eg.Color.BLACK)
13.
14. select cat
15. from Cat cat
16. join cat.kittens kitten
17. group by cat
18. having avg(kitten.weight) > 100
19. order by count(kitten) asc, sum(kitten.weight) desc
9.子查询
1. from Cat as fatcat
2. where fatcat.weight > (select avg(cat.weight) from DomesticCat cat)
3.
4. from Cat as cat
5. where not (cat.name, cat.color) in (
6. select cat.name, cat.color from DomesticCat cat
7. )
10.fetch关键字
1. from Person as p join p.scores
2. from Document fetch all properties order by name
3. from Document doc fetch all properties where lower(doc.name) like '%cat%'
11.命名查询
1. <!--定义命名查询-->
2. <query name="myNamedQuery">
3. <!--此处确定命名查询的HQL语句-->
4. from Person as p where p.age > ?
5. </query>
调用命名查询的示例代码如下:
1. private void findByNamedQuery() throws Exception {
2. Session session = HibernateUtil.currentSession();
3. Transaction tx = session.beginTransaction();
4. System.out.println("执行命名查询");
5. //调用命名查询
6. List pl = sess.getNamedQuery("myNamedQuery")
7. //为参数赋值
8. .setInteger(0, 20)
9. //返回全部结果
10. .list();
11. //遍历结果集
12. for (Integer pit = pl.iterator(); pit.hasNext(); )
13. {
14. Person p = (Person)pit.next();
15. System.out.println(p.getName());
16. }
17. tx.commit();
18. HibernateUtil.closeSession();
19. }
HQL是完全面向对象的查询语言,因此可以支持继承和多态等特征。
HQL查询依赖于Query类,每个Query实例对应一个查询对象,使用HQL查询按
如下步骤进行:
(1)获取Hibernate Session对象;
(2)编写HQL语句;
(3)以HQL语句作为参数,调用Session的createQuery方法创建查询对象;
(4)如果HQL语句包含参数,调用Query的setXxx方法为参数赋值;
(5)调用Query对象的list等方法遍历查询结果。
查询示例:
1. public class HqlQuery
2. {
3. public static void main(String[] args) throws Exception {
4. HqlQuery mgr = new HqlQuery();
5. //调用查询方法
6. mgr.findPersons();
7. //调用第二个查询方法
8. mgr.findPersonByHappenDate();
9. HibernateUtil.sessionFactory.close();
10. }
11. //第一个查询方法
12. private void findPersons() {
13. //获得Hibernate Session
14. Session sess = HibernateUtil.currentSession();
15. //开始事务
16. Transaction tx = sess.beginTransaction();
17. //以HQL语句创建Query对象
18. //执行setString方法为HQL语句的参数赋值
19. //Query调用list方法访问查询的全部实例
20. List p1 = sess.createQuery("from Person p where o.myEvents.title = :
21. eventTitle").setString("eventTitle", "很普通事情").list();
22. //遍历查询的全部结果
23. for (Iterator pit = p1.iterator(); pit.haxNext(); )
24. {
25. Person p = (Person)pit.next();
26. System.out.println(p.getName());
27. }
28. //提交事务
29. tx.commit();
30. HibernateUtil.closeSession();
31. }
32. //第二个查询方法
33. private void findPersonByHappenDate() throws Exception {
34. Session sess = HibernateUtil.currentSession();
35. Transaction tx = sess.beginTransaction();
36. //解析出Date对象
37. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
38. Date start = sdf.parse("2007-11-27");
39. System.out.println("系统开始通过日期查找人" + start);
40. //通过Session的createQuery方法创建Query对象
41. //设置参数
42. //返回结果集
43. List pl = sess.createQuery(
44. "from Person p where p.myEvents.happenDate between :firstDate
45. and :endDate")
46. .setDate("firstDate", start)
47. .setDate("endDate", new Date())
48. .list();
49. //遍历结果集
50. for (Iterator pit = pl.iterator(); pit.hasNext(); )
51. {
52. Person p = (Person)pit.next();
53. System.out.println(p.getName());
54. }
55. tx.commit();
56. HibernateUtil.closeSession();
57. }
58. }
$下面介绍HQL语句的语法
1.from子句
1. from Person
表明从Person持久化类中选出全部的实例。
推荐:from Person as p
2.select子句
1. select p.name from Person as p
2. select p.name.firstName from Person as p
3. select new list(p.name, p.address) from Person as p
4. select new ClassTest(p.name, p.address) from Person as p (有前提)
5. select p.name as personName from Person as p
6. select new map(p.name as personName) from Person as p (与new map()结合更普遍)
3.聚集函数
1. avg,count,max,min,sum
2. select count(*) from Person
3. select max(p.age) from Person as p
4. select p.name || "" || p.address from Person as p
4.多态查询
1. from Person as p
2. from java.lang.Object o
3. from Named as n
5.where子句
1. from Person where name like "tom%"
2. from Person as p where p.name like "tom%"
3. from Cat cat where cat.mate.name like "kit%"
4. select * from cat_table as table1 cat_table as table2 where table1.mate =
5. table2.id and table1.name like "kit%"
6. from Foo foo where foo.bar.baz.customer.address.city like "fuzhou%"
7. from Cat cat, Cat rival where cat.mate = rival.mate
8. select cat, mate
9. from Cat cat, Cat mate
10. where cat.mate = mate
11. from Cat as cat where cat.id = 123
12. from Cat as cat where cat.mate.id = 69
13. from Person as person
14. where person.id.country = 'AU'
15. and person.id.medicareNumber = 123456
16. from Account as account
17. where account.owner.id.country = 'AU'
18. and account.owner.id.medicareNumber = 123456
19. from Cat cat where cat.class = DomesticCat
20. from Account as a where a.person.name.firstName like "dd%" // 正确
21. from Account as a where a.person.name like "dd%" // 错误
6.表达式
1. from DomesticCat cat where cat.name between 'A' and 'B'
2. from DomesticCat cat where cat.name in ('Foo', 'Bar', 'Baz')
3. from DomesticCat cat where cat.name not between 'A' and 'B'
4. from DomesticCat cat where cat.name not in ('Foo', 'Bar', 'Baz')
5. from DomesticCat cat where cat.name is null
6. from Person as p where p.address is not null
7. <property name="hibernate.query.substitutions">true 1, false 0</property>
8. from Cat cat where cat.alive = true
9. from Cat cat where cat.kittens.size > 0
10. from Cat cat where size(cat.kittens) > 0
11. from Calendar cal where maxelement(cal.holidays) > current date
12. from Order order where maxindex(order.items) > 100
13. from Order order where minelement(order.items) > 10000
14. //操作集合元素
15. select mother from Cat as mother, Cat as kit
16. where kit in elements(foo.kittens)
17. //p的name属性等于集合中某个元素的name属性
18. select p from NameList list, Person p
19. where p.name = some elements(list.names)
20. //操作集合元素
21. from Cat cat where exists elements(cat.kittens)
22. from Player p where 3 > all elements(p.scores)
23. from Show show where 'fizard' in indices(show.acts)
24. //items是有序集合属性,items[0]代表第一个元素
25. from Order order where order.items[0].id = 1234
26. //holidays是map集合属性,holidays[national day]是代表其中第一个元素
27. select person from Person person, Calendar calendar
28. where calendar.holidays['national day'] = person.birthDay
29. and person.nationality.calendar = calendar
30. //下面同时使用list集合和map集合属性
31. select item from Item item, Order order
32. where order.items[order.deliveredItemIndices[0]] = item and order.id = 11
33. select item from Item item, Order order
34. where order.items[maxindex(order.items)] = item and order.id = 11
35.
36. select item from Item item, Order order
37. where order.items[size(order.items) - 1] = item
38.
39. select cust
40. from Product prod,
41. Store store
42. inner join store.customers cust
43. where prod.name = 'widget'
44. and store.location.name in ['Melbourne', 'Sydney']
45. and prod = all elements(cust.currentOrder.lineItems)
46.
47. SELECT cust.name, cust.address, cust.phone, cust.id, cust.current_order
48. FROM customers cust,
49. stores store,
50. locations loc,
51. store_customers sc,
52. product prod
53. WHERE prod.name = 'widget'
54. AND store.loc_id = loc.id
55. AND loc.name IN ('Melbourne', 'Sydney')
56. AND sc.store_id = store.id
57. AND sc.cust_id = cust.id
58. AND prod.id = ALL(
59. SELECT item.prod_id
60. FROM line_items item, orders o
61. WHERE item.order_id = o.id
62. AND cust.current_order = o.id
63. )
7.order by子句
1. from Person as p
2. order by p.name, p.age
3. from Person as p
4. order by p.name asc, p.age desc
8.group by子句
1. select cat.color, sum(cat.weight), count(cat)
2. from Cat cat
3. group by cat.color
4. //select后出现的id处出现在group by之后,而name属性则出现在聚集函数中
5. select foo.id, avg(name), max(name)
6. from Foo foo join foo.names name
7. group by foo.id
8.
9. select cat.color, sum(cat.weight), count(cat)
10. from Cat cat
11. group by cat.color
12. having cat.color in (eg.Color.TABBY, eg.Color.BLACK)
13.
14. select cat
15. from Cat cat
16. join cat.kittens kitten
17. group by cat
18. having avg(kitten.weight) > 100
19. order by count(kitten) asc, sum(kitten.weight) desc
9.子查询
1. from Cat as fatcat
2. where fatcat.weight > (select avg(cat.weight) from DomesticCat cat)
3.
4. from Cat as cat
5. where not (cat.name, cat.color) in (
6. select cat.name, cat.color from DomesticCat cat
7. )
10.fetch关键字
1. from Person as p join p.scores
2. from Document fetch all properties order by name
3. from Document doc fetch all properties where lower(doc.name) like '%cat%'
11.命名查询
1. <!--定义命名查询-->
2. <query name="myNamedQuery">
3. <!--此处确定命名查询的HQL语句-->
4. from Person as p where p.age > ?
5. </query>
调用命名查询的示例代码如下:
1. private void findByNamedQuery() throws Exception {
2. Session session = HibernateUtil.currentSession();
3. Transaction tx = session.beginTransaction();
4. System.out.println("执行命名查询");
5. //调用命名查询
6. List pl = sess.getNamedQuery("myNamedQuery")
7. //为参数赋值
8. .setInteger(0, 20)
9. //返回全部结果
10. .list();
11. //遍历结果集
12. for (Integer pit = pl.iterator(); pit.hasNext(); )
13. {
14. Person p = (Person)pit.next();
15. System.out.println(p.getName());
16. }
17. tx.commit();
18. HibernateUtil.closeSession();
19. }
发表评论
-
Spring官网改版后下载
2014-04-11 10:39 769Spring官网改版后找了好久都没有找到直接下载Jar包的链接 ... -
Java 系统架构设计
2014-03-31 21:18 1481首先分为网关和引擎等多个部分: 第一部分:网关 1、主要负责转 ... -
Java 提高系统性能
2014-03-03 22:22 2611首先是从三方面来提高的,应用层面,服务器端层面,数据库层面。 ... -
2013年11月份艺龙旅行网面试题
2013-11-22 23:39 12611.给你两个字符串s1="abc",s2= ... -
国猪555555555
2013-11-22 00:16 1095国足第一招:场地太差,不适应。 国足第二招:场地太好,不适应。 ... -
自己认为的一些技术点
2013-08-14 00:12 12391.rest风格的编程。 2.memcached的命中率低的问 ... -
HttpClient
2013-01-14 23:57 1050package org.abin.lee.test.http; ... -
JAVA单例模式读取properties配置文件
2012-12-16 01:12 2665前段时间出差去做一个数据接口的项目,有很多参数需要从工程中的配 ... -
Java 反射调用方法
2012-10-22 23:52 976package lc.abin.lee.reflect; i ... -
Java Https单向,双向验证
2012-09-23 22:47 3010https一般来说有单项SSL和双向SSL连接之分。 单项 ... -
Java中的transient,volatile和strictfp关键字
2012-09-12 18:00 833http://www.iteye.com/topic/5295 ... -
Server JBoss v5.0 at localhost was unable to start within 50 seconds.
2012-09-05 11:35 1883[标题]:[转]JBoss was unable to sta ... -
HttpUrlConnection 开发例子
2012-03-25 16:23 3359/*** * * 发送HTTP请求 * @ ... -
Java Enum类型定义的方法
2012-03-12 12:34 2346//枚举接口 package com.abin.info.s ... -
Rational Rose 2003 下载及破解方法
2012-03-06 12:49 1392FROM:http://blog.csdn.net/fengl ... -
使用Spring进行面向切面(AOP)编程
2012-02-22 10:35 23451.aop理论知识 横切性关注点:对哪些方法拦截,拦截后怎么处 ... -
BASE64、MD5、SHA、HMAC几种加密算法
2012-02-21 12:53 8805BASE64编码算法不算是真正的加密算法。 MD5、 ... -
文本文件和二进制文件区别及java中字节流和字符流归纳
2012-02-17 15:48 2991首先在物理上文本文件和二进制文件并没有区别,都是以二进制01的 ... -
Java 字节流转化为文件
2012-02-17 15:46 5750已知:byte[] bytes=new FileToBytes ... -
Java核心之Java内存分配原理
2012-02-17 13:40 952JAVA内存分配与管理是Java的核心技术之一,之前我们曾介绍 ...
相关推荐
2. **编写HQL语句**:明确查询目标及查询条件。 3. **创建查询对象**:使用`Session`对象的`createQuery`方法创建`Query`对象。 4. **设置参数**:如果HQL语句中有参数,则需通过`setQuery`方法为其赋值。 5. **执行...
《Hibernate HQL查询语法详解》 Hibernate,作为Java领域中广泛应用的对象关系映射(ORM)框架,极大地简化了数据库操作。其内置的HQL(Hibernate Query Language)是一种面向对象的查询语言,它允许开发者以类和...
HQL语句的语法结构与SQL相似,但更注重对象和类的概念。以下将详细介绍HQL语句的几个关键部分: 1. **from 子句**:这是HQL查询的起点,用于指定要查询的持久化类。例如,`from Person as p`表示从`Person`类中选择...
#### 三、HQL语法详解及示例 下面将详细介绍HQL中的几种常见语法及其应用场景。 ##### 1. `FROM`子句 用于指定查询的目标对象或类。例如,查询所有Person对象: ```java from Person ``` 该语句返回的是Person表中...
HQL查询实体时,基本语法为`FROM`后面跟实体类名。例如,查询所有用户可以这样写: ```java String hql = "FROM User user"; List<User> list = session.createQuery(hql).list(); ``` HQL也支持`WHERE`子句,用于...
在深入探讨HQL语法之前,我们首先需要理解什么是HQL。HQL,全称为Hibernate Query Language,是Hibernate框架提供的一种面向对象的查询语言。与SQL(Structured Query Language)不同,HQL是专为ORM(Object-...
### HQL语法总结:实体查询详解 #### 一、实体查询概述 HQL(Hibernate Query Language)是一种面向对象的查询语言,它允许开发者以一种类似于SQL但更接近于面向对象的方式来编写查询。本文将详细介绍HQL中的实体...
### Spring框架中HQL查询方法详解 在Spring框架与Hibernate技术结合使用时,HQL(Hibernate Query Language)作为对象查询语言被广泛应用于数据查询操作之中。本文将详细解析Spring框架中常用的HQL查询方法及其应用...
Hibernate HQL关联查询遵循了SQL中连接查询的概念,但在语法上有所区别,使其更符合面向对象编程的习惯。Hibernate支持以下几种连接查询方式: 1. **内连接(Inner Join)**:`INNER JOIN` 或 `JOIN` ```java ...
### HQL语句语法详解 HQL(Hibernate Query Language)是一种面向对象的查询...通过以上介绍,我们可以看到HQL不仅提供了丰富的语法结构,还支持面向对象的查询方式,极大地简化了数据库查询操作,提高了开发效率。
HQL的基本语法** HQL查询语句结构通常包括以下几个部分:`SELECT`, `FROM`, `WHERE`, `GROUP BY`, `HAVING`, `ORDER BY`。这些关键字与SQL中的用法类似,但HQL中的对象和属性是基于Java类和它们的成员。 例如,...
本文将深入探讨HQL多表查询的核心概念、语法结构以及实际应用案例。 ### HQL多表查询的基础概念 HQL支持多种查询方式,包括单表查询、多表查询、连接查询等。其中,多表查询是处理复杂数据关系的关键技术,它允许...
2. **易于理解**:HQL的语法结构清晰,容易理解和学习。 3. **平台无关**:由于HQL是基于Hibernate框架的查询语言,因此不受特定数据库的影响,可以在不同的数据库平台上无缝迁移。 4. **灵活性**:HQL支持多种查询...
Hibernate 查询语言(HQL)语法参考 HQL(Hibernate Query Language)是 Hibernate 框架中的一种强大的查询语言,它类似于 SQL 语句,但是它是完全面向对象的查询语言,可以理解继承、多态和关联等概念。 大小写...
HQL 的基本语法: * from 子句:在 Hibernate 中实现数据库表中的数据查询。 * select 子句:选择将对象的属性返回到查询结果集中。 * where 子句:允许你将返回的对象的实例列表的范围缩小。 HQL 的应用示例: *...
2. **编写HQL语句**:HQL的语法类似于SQL,但更注重对象。例如,`from Person p where p.myEvents.title = :eventTitle`这样的查询语句会找出所有`myEvents`标题为`eventTitle`的`Person`对象。 3. **创建Query对象*...
本教程聚焦于“完善HibernateUtil类及HQL查询入门”,让我们深入探讨这两个关键概念。 首先,`HibernateUtil` 类是 Hibernate 教程中常见的一种工具类,它的主要作用是提供对 Hibernate 框架的简单封装,以方便进行...