public void testload2() {
Session session = null;
Group group = null;
try {
session = HibernateUtils.getSession();
session.beginTransaction();
group = (Group) session.load(Group.class, 1);
[color=red]
System.out.println("group.name=" + group.getName());[/color]
session.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
} finally {
HibernateUtils.closeSession(session);
}
// could not initialize proxy - the owning Session was closed
// LazyInitializationException:
[color=brown]System.out.println("group.name=" + group.getInfo());[/color]
}
大家帮我看看,如果加上System.out.println("group.name=" + group.getName())这段代码就不会抛出LazyInitializationException,如果不加就会出现LazyInitializationException,不知道为什么,不都关闭了session了吗?