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- 子查询的更多相关文章

  1. hibernate子查询

    对于支持子查询的数据库,Hibernate支持在查询中使用子查询.一个子查询必须被圆括号包围起来(经常是SQL聚集函数的圆括号). 甚至相互关联的子查询(引用到外部查询中的别名的子查询)也是允许的. ...

  2. 关于hibernate子查询参数的问题

    private Map<String, Object> createWblHqlContext(boolean needGroup, String startDate, String en ...

  3. 利用Hibernate子查询(in) 得到部分字段(实体类的构造函数)

    感人= = 终于弄好了 String hql="select new Shop(s.strid,s.shopname,s.tradearea,s.discountinfo,s.beginti ...

  4. Hibernate 分组查询 子查询 原生SQL

    分组查询: 使用group by关键字对数据分组,使用having关键字对分组数据设定约束条件,从而完成对数据分组和统计 1.1 聚合函数:常被用来实现数据统计功能 ① count() 统计记录条数 ...

  5. Hibernate HQL中的子查询

    子查询是SQL语句中非常重要的功能特性,它可以在SQL语句中利用另外一条SQL语句的查询结果,在Hibernate中HQL查询同样对子查询功能提供了支持.   如下面代码所示: List list=s ...

  6. Hibernate 函数 ,子查询 和原生SQL查询

    一. 函数 聚合函数:count(),avg(),sum(),min(),max() 例:(1)查询Dept表中的所有的记录条数. String hql=" select count(*) ...

  7. hibernate的子查询

    hibernate原话 HQL supports subqueries in the where clause. We can't think of many good uses for subque ...

  8. Hibernate 笔记 HQL查询 条件查询,聚集函数,子查询,导航查询

    在hibernate中进行多表查询,每个表中各取几个字段,也就是说查询出来的结果集并没有一个实体类与之对应,如何解决这个问题? 解决方案一,按照Object[]数据取出数据,然后自己组bean 解决方 ...

  9. Hibernate中使用子查询

    子查询:   子查询是SQL语句中非常重要的功能特性,它可以在SQL语句中利用另外一条SQL语句的查询结果,在Hibernate中HQL查询同样对子查询功能提供了支持.   如下面代码所示: List ...

  10. [转]HQL中的子查询

    原文地址:http://blog.csdn.net/xb12369/article/details/8638683 子查询:   子查询是SQL语句中非常重要的功能特性,它可以在SQL语句中利用另外一 ...

随机推荐

  1. Android ——真机调试

    1. 设置android手机为USB调试模式.步骤: menu---> 设置 ---> 应用程序 ---> 开发 , 选择[USB调试] 2. 用USB连接手机和电脑,并确保成功.步 ...

  2. HTML中button和input button的区别

    button和input button的区别 一句话概括主题:<button>具有<input type="button" ... >相同的作用但是在可操控 ...

  3. Socket详解-Linux Socket编程(不限Linux)

    “一切皆Socket!” 话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的socket. ——有感于实际编程和开源项目研究. 我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览 ...

  4. Linux时间子系统(十六) clockevent

    一.clock event控制的通用逻辑 1.产生clock event的设备 各种系统的timer硬件形形色色,不过在general clock event device layer,struct ...

  5. python标准库介绍——19 mmap 模块详解

    ==mmap 模块== (2.0 新增) ``mmap`` 模块提供了操作系统内存映射函数的接口, 如 [Example 2-13 #eg-2-13] 所示. 映射区域的行为和字符串对象类似, 但数据 ...

  6. 计算机通信协议之OSI参考模型

    OSI参考模型 在OSI参考模型之前人类对计算机结构的研究就已经进行了太多的讨论,最终通过了作为通信协议设计指标的OSI参考模型.这个协议将通信协议中必要的功能分成了七个部分.通过这些分层使得那些比较 ...

  7. Vert.x中EventBus中的使用

    注意:使用的是vert.x3.0 仅支持到java8当中有一些lambda表达式.如不明确请自补java8新特性. The Event Bus event bus 是vert.x的神经系统. 每个ve ...

  8. ThinkPad 预装win8换win7(软激活)

    今天晚上有人叫我给他装系统,没错!这就是计算机专业的拿手技能(维修学院重装系统专业Win7系统班^-^). 一拿手上,是lenovo的ThinkPad E430型号,预装的系统是win8,由于win8 ...

  9. Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(3)

    Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(3) 一.配置共享存储 [oracle@aix203 ~]$lsdev -c disk hdisk0 Available ...

  10. JDK自带工具之问题排查场景示例

    最近看到了大量关于java性能调优.故障排查的文章,自己也写了一篇< Java调优经验谈 >.接着此篇文章,其实一直打算写写一些常用调优工具以及它们的惯常用法的.后来在http://jav ...