wbs5520
2011-10-08 21:36hibernate对象状态问题
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然后我能够使用
- 点赞
- 回答
- 收藏
- 复制链接分享
4条回答
为你推荐
- 求助,Java-SpringBoot应用查询id返回的值为null,但是在数据库查询是有结果的,应当如何解决呢?
- java
- java-ee
- spring
- maven
- mysql
- 2个回答
- hibernate 不用事务,也提交到了数据库,帮忙看看
- spring
- hibernate
- 0个回答
- hibernate对象状态问题
- hibernate
- 0个回答
- 关于hibernate 事务提交的问题
- hibernate
- 0个回答
- hibernate异常update: 0 actual row count: 0 expected: 1
- hibernate
- 0个回答