01.搭建开发环境

02.连接查询

package com.gordon.test;

import java.util.Arrays;
import java.util.List; import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test; import com.gordon.domain.Book;
import com.gordon.domain.Publisher;
import com.gordon.utils.HibernateUtil; /**
* 连接查询
* @author Administrator
*/
public class TestDemo5 { /**
* 连接查询-右外连接
* 查询结果
Hibernate:
select
book0_.id as id1_0_0_,
publisher1_.id as id1_1_1_,
book0_.name as name2_0_0_,
book0_.price as price3_0_0_,
book0_.publisher_id as publishe4_0_0_,
publisher1_.name as name2_1_1_
from
t_book book0_
left outer join
t_publisher publisher1_
on book0_.publisher_id=publisher1_.id
云计算技术及性能优化
---电子工业出版社
C语言程序设计
---电子工业出版社
中国冰雪梦
---电子工业出版社
Photoshop图形图像处理
---北京大学出版社
VisualBasic2015实践教程
---北京大学出版社
生产微服务
---人民邮电出版社
架构探险:轻量级微服务架构(下册)
---人民邮电出版社
*/
@Test
public void run4() {
Session session = HibernateUtil.getCurrentSession();
Transaction transaction = session.beginTransaction(); String hql = "from Book b right join b.publisher p";
Query query = session.createQuery(hql); Book b = null;
Publisher p = null; List<Object[]> list = query.list();
for (Object[] book : list) { b = (Book) book[0];
p = (Publisher) book[1]; System.out.println(b.getName());
System.out.println("---" + p.getName());
} transaction.commit();
} /**
* 连接查询-左外连接
* 查询结果
Hibernate:
select
book0_.id as id1_0_0_,
publisher1_.id as id1_1_1_,
book0_.name as name2_0_0_,
book0_.price as price3_0_0_,
book0_.publisher_id as publishe4_0_0_,
publisher1_.name as name2_1_1_
from
t_book book0_
left outer join
t_publisher publisher1_
on book0_.publisher_id=publisher1_.id
云计算技术及性能优化
---电子工业出版社
C语言程序设计
---电子工业出版社
中国冰雪梦
---电子工业出版社
Photoshop图形图像处理
---北京大学出版社
VisualBasic2015实践教程
---北京大学出版社
生产微服务
---人民邮电出版社
架构探险:轻量级微服务架构(下册)
---人民邮电出版社
*/
@Test
public void run3() {
Session session = HibernateUtil.getCurrentSession();
Transaction transaction = session.beginTransaction(); String hql = "from Book b left join b.publisher p";
Query query = session.createQuery(hql); Book b = null;
Publisher p = null; List<Object[]> list = query.list();
for (Object[] book : list) { b = (Book) book[0];
p = (Publisher) book[1]; System.out.println(b.getName());
System.out.println("---" + p.getName());
} transaction.commit();
} /**
* 连接查询-隐式内连接
* 查询结果
Hibernate:
select
book0_.id as id1_0_0_,
publisher1_.id as id1_1_1_,
book0_.name as name2_0_0_,
book0_.price as price3_0_0_,
book0_.publisher_id as publishe4_0_0_,
publisher1_.name as name2_1_1_
from
t_book book0_ cross
join
t_publisher publisher1_
where
book0_.publisher_id=publisher1_.id
云计算技术及性能优化
---电子工业出版社
C语言程序设计
---电子工业出版社
中国冰雪梦
---电子工业出版社
Photoshop图形图像处理
---北京大学出版社
VisualBasic2015实践教程
---北京大学出版社
生产微服务
---人民邮电出版社
架构探险:轻量级微服务架构(下册)
---人民邮电出版社
*/
@Test
public void run2() {
Session session = HibernateUtil.getCurrentSession();
Transaction transaction = session.beginTransaction(); String hql = "from Book b, Publisher p where b.publisher = p";
Query query = session.createQuery(hql); Book b = null;
Publisher p = null; List<Object[]> list = query.list();
for (Object[] book : list) { b = (Book) book[0];
p = (Publisher) book[1]; System.out.println(b.getName());
System.out.println("---" + p.getName());
} transaction.commit();
} /**
* 连接查询-显示内连接
* 查询结果
Hibernate:
select
book0_.id as id1_0_0_,
publisher1_.id as id1_1_1_,
book0_.name as name2_0_0_,
book0_.price as price3_0_0_,
book0_.publisher_id as publishe4_0_0_,
publisher1_.name as name2_1_1_
from
t_book book0_
inner join
t_publisher publisher1_
on book0_.publisher_id=publisher1_.id
云计算技术及性能优化
---电子工业出版社
C语言程序设计
---电子工业出版社
中国冰雪梦
---电子工业出版社
Photoshop图形图像处理
---北京大学出版社
VisualBasic2015实践教程
---北京大学出版社
生产微服务
---人民邮电出版社
架构探险:轻量级微服务架构(下册)
---人民邮电出版社
*/
@Test
public void run1() {
Session session = HibernateUtil.getCurrentSession();
Transaction transaction = session.beginTransaction(); String hql = "from Book b inner join b.publisher";
Query query = session.createQuery(hql); Book b = null;
Publisher p = null; List<Object[]> list = query.list();
for (Object[] book : list) { b = (Book) book[0];
p = (Publisher) book[1]; System.out.println(b.getName());
System.out.println("---" + p.getName());
} transaction.commit();
}
}

最新文章

  1. IOS随机随学
  2. Web Service 的工作原理
  3. Linux 系统常用命令汇总(二) vi 文本编辑
  4. python_way ,json(自学)
  5. Spring For Android初体验
  6. 通过开发工具发布web应用到tomcat服务器中--对于小白,大神可以忽略不看,勿喷,谢谢
  7. 仿bootstrap的
  8. log4j2配置MDC分线程写日志
  9. Tsinsen-A1488 : 魔法波【高斯消元+异或方程组】
  10. Asp.net SignalR 应用并实现群聊功能 开源代码
  11. git笔记--git@OSC
  12. NPOI json转Excel DataTable转Excel ,Excel转DataTable
  13. 201621123060《JAVA程序设计》第九周学习总结
  14. Linux设备树语法详解【转】
  15. app与jvm 反向代理时config的设置(用于在web页面显示npm(就如tomcat)产生的页面)
  16. elasticsearch权威指南
  17. Linux indent命令
  18. CSS的定位问题总结
  19. 【BZOJ2622】[2012国家集训队测试]深入虎穴 次短路
  20. 通过自动回复机器人学Mybatis:代码重构(分层)

热门文章

  1. WebADI_WebADI工作日志设定(案例)
  2. Python hypot() 函数
  3. 【转】Ubuntu VI基本用法
  4. unity, 荧光效果(bloom)
  5. jquery中选择块并改变属性值的方法
  6. C#匿名对象的使用
  7. PCIE知识点
  8. Dos.ORM logo.Net轻量级开源ORM框架 Dos.ORM
  9. JSP版LCX:端口转发神器 KPortTran
  10. C语言可变参数宏及‘##’在可变参数中的作用