标签:obj stat ack create 框架 nts creat lap pack
package cn.itcast.h3.hql; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import cn.itcast.h3.hql.vo.StudentModel; import cn.itcast.h3.hql.vo.TeacherModel; import cn.itcast.h3.util.HibernateUtil; //多表查询 public class MulHQLApp { //内连接 void testMulInner(){ Session s = HibernateUtil.getSession(); Query q = s.createQuery("from TeacherModel tm inner join tm.students s"); List<Object[]> queryList = q.list(); System.out.println(queryList.size()); for(Object[] objs:queryList){ for(Object obj:objs){ System.out.print(obj+"\t"); } System.out.println(); } s.close(); } //迫切内连接 void testMulInner2(){ Session s = HibernateUtil.getSession(); Query q = s.createQuery("select DISTINCT tm from TeacherModel tm inner join fetch tm.students s"); List<Object> queryList = q.list(); System.out.println(queryList.size()); for(Object obj:queryList){ System.out.println(obj); } s.close(); } //隐式内连接 void testMulInner3(){ Session s = HibernateUtil.getSession(); Query q = s.createQuery("from TeacherModel"); List<Object> queryList = q.list(); System.out.println(queryList.size()); for(Object obj:queryList){ System.out.println(obj); } s.close(); } //左外连接 void testMulOuter1(){ Session s = HibernateUtil.getSession(); Query q = s.createQuery("from TeacherModel tm left outer join tm.students s"); List<Object[]> queryList = q.list(); System.out.println(queryList.size()); for(Object[] objs:queryList){ for(Object obj:objs){ System.out.print(obj+"\t"); } System.out.println(); } s.close(); } //迫切左外连接 void testMulOuter2(){ Session s = HibernateUtil.getSession(); Query q = s.createQuery("from TeacherModel tm left outer join fetch tm.students s"); List<Object> queryList = q.list(); System.out.println(queryList.size()); for(Object obj:queryList){ System.out.println(obj); } s.close(); } //右外连接 void testMulOuter3(){ Session s = HibernateUtil.getSession(); Query q = s.createQuery("from TeacherModel tm right outer join tm.students s"); List<Object[]> queryList = q.list(); for(Object[] objs:queryList){ for(Object obj:objs){ System.out.print(obj+"\t"); } System.out.println(); } s.close(); } void fn(){ Session s = HibernateUtil.getSession(); Query q = s.createQuery("from TeacherModel"); List<TeacherModel> queryList = q.list(); // System.out.println(((TeacherModel)queryList.get(0)[0]).getStudents()); // System.out.println(((StudentModel)queryList.get(0)[1]).getTeacher()); System.out.println(queryList.get(0).getStudents()); s.close(); } void fn1(){ Session s = HibernateUtil.getSession(); Query q = s.createQuery("from TeacherModel tm right outer join tm.students s"); List<Object[]> queryList = q.list(); System.out.println(((TeacherModel)queryList.get(35)[0]).getStudents()); // System.out.println(((StudentModel)queryList.get(0)[1]).getTeacher()); // System.out.println(queryList.get(30).getStudents().size()); s.close(); } public static void main(String[] args) { new MulHQLApp().fn1(); } } /* List<Object> queryList = q.list(); for(Object obj:queryList){ System.out.println(obj); } List<Object[]> queryList = q.list(); for(Object[] objs:queryList){ for(Object obj:objs){ System.out.print(obj+"\t"); } System.out.println(); } */
标签:obj stat ack create 框架 nts creat lap pack
原文地址:https://www.cnblogs.com/xyhero/p/9351721.html