public static void testload(){
/**
* 通过load的方式加载对象时,会使用延迟加载机制,此时得到的Student对象其实是一个代理对象
*/
Student stu =(Student)session.load(Student.class,1);
System.out.println(stu);//可以打个断点看看,有个代理对象。

//如果没这条数据会空指针
Student s =(Student)session.load(Student.class,100);
System.out.println(s);//org.hibernate.ObjectNotFoundException: No row with the given identifier exists
}
public static void testget(){
Student stu=(Student)session.get(Student.class, 1);
System.out.println(stu);//可以打个断点看看,全部都有值。

//没数据会报找不到对象
Student s=(Student)session.get(Student.class, 100);
System.out.println(s);//null
}
load get的区别:
1.当使用get方法加载获取对象时,它会第一时间执行SQL到数据库查询,整个对象给返回出来。