org.hibernate.LazyInitializationException: could not initialize proxy - no Session

查询id报了一个 no Session 问题

    @Test
    public void testQuery(){
        //查询id为1的客户
        Customer customer = customerDao.getOne(1l);
        //对象导航查询,此客户下的所有联系人
        Set linkMan = customer.getLinkMans();
        for (LinkMan man : linkMan) {
            System.out.println(man);
        }
    }

org.hibernate.LazyInitializationException: could not initialize proxy - no Session_第1张图片

解决办法

    @Test
    @Transactional
    public void testQuery(){
        //查询id为1的客户
        Customer customer = customerDao.getOne(1l);
        //对象导航查询,此客户下的所有联系人
        Set linkMan = customer.getLinkMans();
        for (LinkMan man : linkMan) {
            System.out.println(man);
        }
    }

org.hibernate.LazyInitializationException: could not initialize proxy - no Session_第2张图片

你可能感兴趣的:(org.hibernate.LazyInitializationException: could not initialize proxy - no Session)