一、查询策略

 

 

 

 二、无迫切连接查询

 1 @Test
 2     public void test1(){
 3 
 4         SessionFactory sessionFactory = getSessionFactory();
 5         Session session = sessionFactory.openSession();
 6         Transaction transaction = session.beginTransaction();
 7 
 8         String hql = " from HTeacherEntity t inner join t.studentEntities s where s.sname = :name";
 9         Query<Object[]> query = session.createQuery(hql).setParameter("name", "学五");
10         for (Object[] objects : query.list()) {
11 
12             System.out.println(Arrays.toString(objects));
13         }
14     }

三、迫切连接查询

 1 @Test
 2     public void test2(){
 3 
 4         SessionFactory sessionFactory = getSessionFactory();
 5         Session session = sessionFactory.openSession();
 6         Transaction transaction = session.beginTransaction();
 7 
 8         //在inner join后加上fetch 同时,返回的结果必须是实体对象
 9         String hql = " from HTeacherEntity t inner join fetch t.studentEntities s where s.sname = :name";
10         Query<HTeacherEntity> query = session.createQuery(hql).setParameter("name", "学五");
11         System.out.println(query.list());
12     }