java

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

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

查询id报了一个 no Session 问题

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

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

解决办法

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

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

0 条回应