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. 使用自定义模板来弥补eclipse没有新建Filter的功能

    http://yufei.iteye.com/blog/125012 eclipse插件,并没有为我们提供Filter的新建功能,为此我们不得不每次都去新建个类,然后输入那繁琐的重复代码,这完全就是浪 ...

  2. Squid调试和故障处理

    http://blog.zhdata.com/tag/squid第16章 调试和故障处理 16.1 一些通用问题 在讨论通用debug前,我先提起一些经常发生的问题. 16.1.1 “Failed t ...

  3. Android HTTP通讯

    这里有一个非常棒的http通讯的总结,我看了以后茅塞顿开. 先贴代码: 01 public class Activity1 extends Activity { 02   03     private ...

  4. configure: error: newly created file is older than distributed files!

    在linux下安装软件包的时候,有时候提示 configure: error: newly created file is older than distributed files!Check you ...

  5. Mosquitto ---学习笔记

    Mosquitto的安装,可以参见:https://mosquitto.org/download/ [基础配置]Mosquitto服务的配置文件为/etc/mosquitto/mosquitto.co ...

  6. [android] 网络断开的监听

    标签: android 网络监听 杂谈 分类: Android [转自]  http://blog.sina.com.cn/s/blog_5d5996d001012o07.html 其实手机在网络方面 ...

  7. 如何发布打包并发布自己的Android应用(APP)

    如何将android项目打包成apk 分类: android 2012-08-29 10:12 1678人阅读 评论(1) 收藏 举报 androideclipseapplicationjdkjava ...

  8. Android开发1——查找所需要出示权限的内容

    一.发现问题 用户在执行一些如拨打电话.发送短信等关系用户隐私的功能时,Android需要出示权限,权限在AndroidManifest.xml中配置 拨打电话的权限 发送短信的权限 那么这些权限信息 ...

  9. THINKPHP导入全部post参数

    @extract($_POST);//导入全部POST参数直接使用变量

  10. 改变mysql数据库用户的权限

    mysql> grant all on *.* to test@'%';Query OK, 0 rows affected (0.00 sec) mysql> flush privileg ...