当get方法查询一个不存在的对象的时候,也就是表中没有这个记录的时候,是不会出现异常的,就不会报错。而load方法就相反了,对象不存在的时候会抛出异常。异常为:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.gis520.model.Emp#3]
at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:419)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:154)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:143)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at com.gis520.model.Emp_$$_javassist_0.toString(Emp_$$_javassist_0.java)
at java.lang.String.valueOf(String.java:2827)
at java.io.PrintStream.println(PrintStream.java:771)
at com.gis520.test.EmpTest.testSelect(EmpTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)