.............
public class Query {
public static void main(String[] args) {
//打开Session取得Student对象,后关闭Session
Student student = getStudent();
//打开另一个Session.调用update()方法,因为在上面的Session关闭后,
//student对象成了脱管状态,在另一个Session中无法初始化一个脱管对象,必须重新关联
HibernateSessionFactory.getSession().update(student.getTeam());
//使用initialize方法初始化一个代理对象或者集合(此代理并不能保证内部嵌套的对象或者集合被初始化)
Hibernate.initialize(student.getTeam());
System.out.println(student.getTeam().getTeamname());
HibernateSessionFactory.closeSession();
}
...
public static Student getStudent() {
StudentDAO studentDAO = new StudentDAO();
Session session = studentDAO.getSession();
Student student = (Student) session.get(Student.class, "2c9ab2d516056609011605660e7e0001");
session.close();
return student;
}
...
}
posted on 2007-11-03 22:17
Ke 阅读(5322)
评论(1) 编辑 收藏 所属分类:
hibernate