JPA-jpql-关联查询

JPQL的关联查询:from Customer c left outer join fetch c.orders where c.id=?

 //JPQL的关联查询同HQL的关联查询
    @Test
    public void testLeftOuterJoinFetch(){
        String jpql="from Customer c left outer join fetch c.orders where c.id=?";
        Customer customer = (Customer) entityManager.createQuery(jpql).setParameter(1, 1).getSingleResult();
        System.out.println(customer.getLastname());
        System.out.println(customer.getOrders().size());
    }


你可能感兴趣的:(JPA-jpql-关联查询)