以下是HibernateUtil类:
public static Object get(Class clazz, int id) throws Exception{
Session s = null;
Transaction tx = null;
try{
s = HibernateUtil.getSession();
tx = s.beginTransaction();
//Object obj = s.get(clazz, id);
Object obj = s.load(clazz, id);
System.out.println("~~~~~~~~~~~~在Hibernate.initialize(obj);之前~~~~~~~~~~~~~~~~");
Hibernate.initialize(obj);
System.out.println("~~~~~~~~~~~~在Hibernate.initialize(obj);之后~~~~~~~~~~~~~~~~");
tx.commit();
return obj;
}catch(Exception e){
if(tx != null){
tx.rollback();
throw e;
}
}finally{
if(s != null)
s.close();
return null;
}
}
然后调用该类的这个get方法:
try{
HibernateUtil.add(user);
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
User tempU = (User)HibernateUtil.get(User.class, 0);
}catch(Exception e){
System.err.println(e);
System.err.println("~~~~~~~~~~~~~~~~~~~~有异常抛出!~~~~~~~~~~~~~~~~");
}finally{
System.out.println("~~~~~~~~~~~~~~~~~~~~~执行完了!~~~~~~~~~~~~~~~"); //为什么这句没有执行呢!
}
输出结果是:
请问:为什么System.out.println(
"~~~~~~~~~~~~~~~~~~~~~执行完了!~~~~~~~~~~~~~~~");没有执行呢!
希望高手指点~~~~