java

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

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

查询id报了一个 no Session 问题

    @Test
    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

解决办法

    @Test
    @T睿共享ransactional
    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 条回应