Model top = new Model();
Set s=new HashSet();
Session session=sf.getCurrentSession();
session.beginTransaction();
top=(Model)session.load(Model.class, (long)1);
session.getTransaction().commit();
System.out.println(top.getName());//在这里会报错没session,怎么回事啊?难道load除的对象就一定要在session中
才能用?
后来我又改了下代码
Model top = new Model();
Set s=new HashSet();
Session session=sf.getCurrentSession();
session.beginTransaction();
top=(Model)session.load(Model.class, (long)1);
System.out.println(top.getName());//在session结束前这里打印一下
session.getTransaction().commit();
System.out.println(top.getName());//这次竟然都能打印不报错了,但是别的操作就不行 ,比如我top.getChildren()就还
是报没session,我是在一个表里面建乐树状结构。
求高手给我说下原理啊! 我怎么才能让对象脱离session然后我能够使用