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. 浅谈 .NET 中的对象引用、非托管指针和托管指针

    目录 前言 一.对象引用 二.值传递和引用传递 三.初识托管指针和非托管指针 四.非托管指针 1.非托管指针不能指向对象引用 2.类成员指针 五.托管指针 前言 本文主要是以 C# 为例介绍 .NET ...

  2. Python学习笔记020——数据库知识概述

    数据库概述 1 提供数据库的软件都有哪些 MySQL.SQL_Server.Oracle.DB2.Mariadb.MongoDB ... (1)是否开源 开源软件:MySQL.Mariadb.Mong ...

  3. WinForm开发,窗体显示和窗体传值相关知识总结

    主窗体中代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void b ...

  4. Spring事务管理实现方式之编程式事务与声明式事务详解(转)

    原文:https://blog.csdn.net/liaohaojian/article/details/70139151 编程式事务 编码方式实现事务管理(代码演示为JDBC事务管理) Spring ...

  5. openstack_swift源代码分析——Swift单机部署

    本文对在单机部署swift 当中每个细节做具体的介绍,并对配置做对应的解释 PC物理机    Ubuntu-12.04-desktop-64位 Swift 版本号:1.13.1 Swift-clien ...

  6. 批处理学习笔记14 - 把所有.mp4文件全部拷贝进统一目录

    今天下载了一套视频教程,结果发现不在同一个目录下,很乱.都放在不同文件夹下. 于是写了一个批处理来解决这个问题 @echo off for /r %%i in (*mp4) do ( copy %%i ...

  7. POJ 2553 The Bottom of Graph 强连通图题解

    Description We will use the following (standard) definitions from graph theory. Let V be a nonempty ...

  8. ny20 吝啬的国度

    吝啬的国度 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市,他有 ...

  9. 09、win32 转换为 store app

    1.机制: 微软的 Project Centernial ( Project C) 项目的就是把传统的 windows桌面应用程序 转换为 windows10 store app (appx). 目的 ...

  10. Tomcat: Could not clean server of obsolete files

    <Context path="/mldn" docBase="E:/web.workspace/mldndemo/WebContent" reloadab ...