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语句中利用另外一 ...
随机推荐
- java socket输入输出中文乱码问题
http://hi.baidu.com/linjk03/item/e2028bfd990c14ea1a111feb 统一了输入输出的编码格式,是不会有乱码问题出现的. 构造Reader或Write ...
- XP系统下建立WIFI热点让手机、电脑能上网
http://wenku.baidu.com/view/372c5b1fa300a6c30c229f42.html 这里记录xp系统下建立共享无线网络连接,若是支持手机设备上的话,网络适配器必须是wi ...
- xcode 在哪里新建category、protocol等文件
1.和以前新建新文件一样.2.当然选IOS啦,不过OS X也有这个选项,然后Objctive-C File. 3.在File Type里选就OK啦.
- Storm 简单介绍
Nimbus :负责资源分配和任务调度, 把任务相关的元信息写入Zookeeper 对应文件夹. Supervisor :负责接受nimbus 分配的任务,启动和停止属于自己管理的worker 进程. ...
- Android github上开源项目、酷炫的交互动画和视觉效果地址集合
Android上开源的酷炫的交互动画和视觉效果:http://blog.csdn.net/u013278099/article/details/50323689 Awesome-android-ui: ...
- OJ刷题---罗马数字转十进制
题目要求: 输入代码: #include<iostream> using namespace std; int main() { int i,j,n,k; int num[7]= {1, ...
- 封ip对爬虫的影响
今天要聊的是封ip对爬虫的影响.我认为封ip能拒绝一部分网络请求,减轻服务器的压力,但是如果要是建立一个好的ip池,封对爬虫的影响不大. 爬取国内一个拍卖公司的网站,刚开始用多进程下载,每分钟能爬取 ...
- linux 调试利器gdb, strace, pstack, pstree, lsof
1) 如何使用strace+pstack利器分析程序性能? http://www.cnblogs.com/bangerlee/archive/2012/04/30/2476190.html 此文有详细 ...
- application , application pool., W3wp ,httpapplication, domain
Hosting and Consuming WCF Services https://msdn.microsoft.com/en-us/library/bb332338.aspx http://www ...
- nyoj576 集齐卡片赢大奖(一)
集齐卡片赢大奖(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 小时候你一定曾经为收集一套三国人物的卡片而买过不少零食吧?这些小吃的袋子里一般都会有一张卡片,如 ...