Hibernate 学习笔记 之 HQL 内连接和迫切内连接
来源:互联网 发布:js window.open 参数 编辑:程序博客网 时间:2024/06/05 18:06
本demo采用5.x以前的query
一、HQL 内连接
以数组的方式进行存储
/*** * HQL 内连接 * * 内连接查询hql语句写法:以客户和联系人为例 * * from Customer c inner join c.setLinkMan */ @Test public void testJoin() { SessionFactory sessionFactory = null; Session session = null; Transaction tx = null; try{ sessionFactory = HibernateUtils.getSessionFactory(); session = sessionFactory.openSession(); tx = session.beginTransaction(); //1.创建query对象 Query query = session.createQuery("from Customer c inner join c.setLinkMan"); List<Customer> list = query.list(); tx.commit(); }catch (Exception e){ tx.rollback(); }finally { session.close(); sessionFactory.close(); } }
二、迫切内连接
以对象的方式进行存储
/** * 迫切内连接 * * 区别:使用内连接返回list中每部分是数组, * 迫切内连接返回list每部分是对象 * * from Customer c inner join fetch c.setLinkMan */ @Test public void testJoin2() { SessionFactory sessionFactory = null; Session session = null; Transaction tx = null; try{ sessionFactory = HibernateUtils.getSessionFactory(); session = sessionFactory.openSession(); tx = session.beginTransaction(); //1.创建query对象 Query query = session.createQuery("from Customer c inner join fetch c.setLinkMan"); List<Customer> list = query.list(); tx.commit(); }catch (Exception e){ tx.rollback(); }finally { session.close(); sessionFactory.close(); } }
三、左外连接
/** * 左外连接 * * from Customer c left outer join c.setLinkMan * * 返回每部分是数组 */ @Test public void testJoin3() { SessionFactory sessionFactory = null; Session session = null; Transaction tx = null; try{ sessionFactory = HibernateUtils.getSessionFactory(); session = sessionFactory.openSession(); tx = session.beginTransaction(); //1.创建query对象 Query query = session.createQuery("from Customer c left outer join c.setLinkMan"); List<Customer> list = query.list(); tx.commit(); }catch (Exception e){ tx.rollback(); }finally { session.close(); sessionFactory.close(); } }
四、迫切左外连接
/** * 迫切左外连接 * from Customer c left outer join fetch c.setLinkMan * * 返回的每部分是对象 */ @Test public void testJoin4() { SessionFactory sessionFactory = null; Session session = null; Transaction tx = null; try{ sessionFactory = HibernateUtils.getSessionFactory(); session = sessionFactory.openSession(); tx = session.beginTransaction(); //1.创建query对象 Query query = session.createQuery("from Customer c left outer join fetch c.setLinkMan"); List<Customer> list = query.list(); tx.commit(); }catch (Exception e){ tx.rollback(); }finally { session.close(); sessionFactory.close(); } }
五、右外连接
/** * 右外连接 * from Customer c right outer join fetch c.setLinkMan */ @Test public void testJoin5() { SessionFactory sessionFactory = null; Session session = null; Transaction tx = null; try{ sessionFactory = HibernateUtils.getSessionFactory(); session = sessionFactory.openSession(); tx = session.beginTransaction(); //1.创建query对象 Query query = session.createQuery("from Customer c right outer join fetch c.setLinkMan"); List<Customer> list = query.list(); tx.commit(); }catch (Exception e){ tx.rollback(); }finally { session.close(); sessionFactory.close(); } }
0 0
- Hibernate 学习笔记 之 HQL 内连接和迫切内连接
- Hibernate迫切左外连接和迫切内连接
- Hibernate框架的内连接和迫切内连接
- 内连接,外连接,交叉连接,迫切左外连接和迫切内连接
- 内连接,迫切内连接,左外连接,迫切左外连接
- 迫切左外连接、 左外连接、 迫切内连接、 内连接
- 内连接,迫切内连接,左外连接,迫切左外连接
- hibernate_day04_13_HQL多表查询(内连接和迫切内连接)
- Hibernate进阶之如何使用Hql内连接,外连接以及自连接
- 关于内连接、左外连接和迫切左外连接
- hibernate HQl中不存在左连接和右连接/内连接(这里指的Hql不是Sql)
- HQL (迫切)左外连接
- HQL内连接语句实测
- 黑马程序员之SQL 学习笔记:数据库的内连接和外连接
- Hibernate中的迫切左外连接和左外连接
- hibernate的迫切连接问题
- Oracle 11g学习笔记--内连接,外连接和自连接
- Oracle 11g学习笔记--内连接,外连接和自连接
- Swift-面向对象,元组,重写,继承,构造,可选值
- HashMap一键对多值的存与取
- Jquery一个简单的注册验证
- 网络图片设置为手机背景
- struts2 com.opensymphony.xwork2.config.ConfigurationException: 异常原因
- Hibernate 学习笔记 之 HQL 内连接和迫切内连接
- 动态设置控件高度
- String处理2
- oracle 递归1:oracle connect by用法
- SpringMVC基础_ControllerAdvice
- 使用AVPlayer自定义支持全屏的播放器(二)
- java获取当前时间的前一个小时
- Toast还能显示图片你知道么?
- centos下安装jdk 还没有验证