Hibernate- 子查询
01.搭建开发环境
02.子查询
package com.gordon.test; import java.util.List; import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test; import com.gordon.domain.Publisher;
import com.gordon.utils.HibernateUtil; /**
* 子查询
*
* @author Administrator
*/
public class TestDemo6 {
/**
* 子查询
* 查询结果:
Hibernate:
select
publisher0_.id as id1_1_,
publisher0_.name as name2_1_
from
t_publisher publisher0_
where
(
select
count(*)
from
t_book books1_
where
publisher0_.id=books1_.publisher_id
)>1
Hibernate:
select
books0_.publisher_id as publishe4_0_0_,
books0_.id as id1_0_0_,
books0_.id as id1_0_1_,
books0_.name as name2_0_1_,
books0_.price as price3_0_1_,
books0_.publisher_id as publishe4_0_1_
from
t_book books0_
where
books0_.publisher_id=?
电子工业出版社3
Hibernate:
select
books0_.publisher_id as publishe4_0_0_,
books0_.id as id1_0_0_,
books0_.id as id1_0_1_,
books0_.name as name2_0_1_,
books0_.price as price3_0_1_,
books0_.publisher_id as publishe4_0_1_
from
t_book books0_
where
books0_.publisher_id=?
北京大学出版社2
Hibernate:
select
books0_.publisher_id as publishe4_0_0_,
books0_.id as id1_0_0_,
books0_.id as id1_0_1_,
books0_.name as name2_0_1_,
books0_.price as price3_0_1_,
books0_.publisher_id as publishe4_0_1_
from
t_book books0_
where
books0_.publisher_id=?
人民邮电出版社2
*/
@Test
public void run1() {
Session session = HibernateUtil.getCurrentSession();
Transaction transaction = session.beginTransaction(); String hql = "from Publisher p where (select count(*) from p.books) > 1"; List<Publisher> list = session.createQuery(hql).list();
for (Publisher publisher : list) {
System.out.println(publisher.getName() + publisher.getBooks().size());
} transaction.commit();
}
}
Hibernate- 子查询的更多相关文章
- hibernate子查询
对于支持子查询的数据库,Hibernate支持在查询中使用子查询.一个子查询必须被圆括号包围起来(经常是SQL聚集函数的圆括号). 甚至相互关联的子查询(引用到外部查询中的别名的子查询)也是允许的. ...
- 关于hibernate子查询参数的问题
private Map<String, Object> createWblHqlContext(boolean needGroup, String startDate, String en ...
- 利用Hibernate子查询(in) 得到部分字段(实体类的构造函数)
感人= = 终于弄好了 String hql="select new Shop(s.strid,s.shopname,s.tradearea,s.discountinfo,s.beginti ...
- Hibernate 分组查询 子查询 原生SQL
分组查询: 使用group by关键字对数据分组,使用having关键字对分组数据设定约束条件,从而完成对数据分组和统计 1.1 聚合函数:常被用来实现数据统计功能 ① count() 统计记录条数 ...
- Hibernate HQL中的子查询
子查询是SQL语句中非常重要的功能特性,它可以在SQL语句中利用另外一条SQL语句的查询结果,在Hibernate中HQL查询同样对子查询功能提供了支持. 如下面代码所示: List list=s ...
- Hibernate 函数 ,子查询 和原生SQL查询
一. 函数 聚合函数:count(),avg(),sum(),min(),max() 例:(1)查询Dept表中的所有的记录条数. String hql=" select count(*) ...
- hibernate的子查询
hibernate原话 HQL supports subqueries in the where clause. We can't think of many good uses for subque ...
- Hibernate 笔记 HQL查询 条件查询,聚集函数,子查询,导航查询
在hibernate中进行多表查询,每个表中各取几个字段,也就是说查询出来的结果集并没有一个实体类与之对应,如何解决这个问题? 解决方案一,按照Object[]数据取出数据,然后自己组bean 解决方 ...
- Hibernate中使用子查询
子查询: 子查询是SQL语句中非常重要的功能特性,它可以在SQL语句中利用另外一条SQL语句的查询结果,在Hibernate中HQL查询同样对子查询功能提供了支持. 如下面代码所示: List ...
- [转]HQL中的子查询
原文地址:http://blog.csdn.net/xb12369/article/details/8638683 子查询: 子查询是SQL语句中非常重要的功能特性,它可以在SQL语句中利用另外一 ...
随机推荐
- Linux 分区注意事项
必须分区: 1)/(根分区) 2)/swap(交换分区,当内存不超过4G时,建议swap大小为内存2倍,若超过4G,建议交换分区跟内存一样大) 推荐分区 /boot(启动分区,单独分区,最新200M)
- ssh/scp 远程连接ssh非默认端口方法
ssh -p port <username>@<IP>
- Python center() 方法
描述 center() 方法返回一个指定的宽度 width 居中的字符串,fillchar 为填充的字符,默认为空格. 语法 center() 方法语法: S.center(width[,fillch ...
- 杭电 1800 Flying to the Mars(贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/Oth ...
- bug list
机型: Samsung Galaxy S GT-I9000 版本: 2.2.1bug: Couldn't create directory for SharedPreferences file xxx ...
- app hybrid
package com.note.testcases; /** * * The MIT License (MIT) * * Copyright (c) 2016 Alejandro Gómez Mor ...
- 怎么从docker中copy文件到 本机
怎么从docker中copy文件到 本机 docker cp <containerId>:/file/path/within/container /host/path/target
- openvpn中tun和tap的区别
openvpn有dev tun和dev tap模式的区别,cookbook的解释是:A TUN device is used mostly for VPN tunnels where only IP- ...
- IP分片
物理网络层一般要限制每次发送数据帧的最大长度.任何时候IP层接受到一份要发送的IP数据报时,它要判断向本地哪个接口发送数据(选路),并查询该接口获得其MTU(最大传输单元:Maximum Transm ...
- [na]win7系统安装在t450s
电脑配置 电脑型号 联想 ThinkPad T450s 笔记本电脑(最近买了个ngff口的128g的固态ssd) 操作系统 Windows 旗舰版 64位 主显卡 集成显卡 IE浏览器 版本号 8.0 ...