标签:object nts 封装 str 一个 多表 distinct for list
1.交叉连接
select * from A ,B
2.内连接 可以省略inner join
隐式内连接:
select * from A,B where A.id = B.aid;
显式内连接:
select * from A inner join B on A.id = B.aid;
迫切内连接:
需要加上fetch关键字
内连接查询两者共有的属性数据。
3.外连接 outer join
左外连接:
select * from A left outer join B on A.id= B.aid;
右外连接:
select * from A right outer join B on A.id = B.aid;
迫切左外连接:需要加上fetch关键字,返回的是对象,不再是数组。
外连接查询共有属性和一方连接的属性
Session session = HibernateUtils.getCurrentSession(); Transaction tx = session.beginTransaction(); // SQL:SELECT * FROM cst_customer c INNER JOIN cst_linkman l ON // c.cust_id = l.lkm_cust_id; // HQL:内连接 from Customer c inner join c.linkMans /* * List<Object[]> list = session.createQuery( * "from Customer c inner join c.linkMans").list(); for (Object[] * objects : list) { System.out.println(Arrays.toString(objects)); } */ // HQL:迫切内连接 其实就在普通的内连接inner join后添加一个关键字fetch. from Customer c inner // join fetch c.linkMans List<Customer> list = session.createQuery("select distinct c from Customer c inner join fetch c.linkMans") .list();// 通知hibernate,将另一个对象的数据封装到该对象中 for (Customer customer : list) { System.out.println(customer); } tx.commit();
标签:object nts 封装 str 一个 多表 distinct for list
原文地址:https://www.cnblogs.com/yanqingguo/p/9757791.html