java

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

rzk · 8月14日 · 2020年本文共417个字 · 预计阅读2分钟135次已读

查询id报了一个 no Session 问题

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

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

解决办法

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

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

0 条回应