我的百度博客    给我留言    Boke宝贝

What on earth have you been doing these days?

统计

留言簿

阅读排行榜

评论排行榜

为什么Hibernate.initialize(obj);后的代码不执行了?

以下是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.class0);
        }
catch(Exception e){
            System.err.println(e);
            System.err.println(
"~~~~~~~~~~~~~~~~~~~~有异常抛出!~~~~~~~~~~~~~~~~");
        }
finally{
            System.out.println(
"~~~~~~~~~~~~~~~~~~~~~执行完了!~~~~~~~~~~~~~~~");    //为什么这句没有执行呢!
        }
输出结果是:
输出结果Hibernate: insert into t_user (userName, `password`, email, id) values (?, ?, ?, ?)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~在Hibernate.initialize(obj);之前~~~~~~~~~~~~~~~~
Hibernate: select user0_.id as id0_0_, user0_.userName as userName0_0_, user0_.`password` as password3_0_0_, user0_.email as email0_0_ from t_user user0_ where user0_.id=?
~~~~~~~~~~~~~~~~~~~~~执行完了!~~~~~~~~~~~~~~~
请问:为什么System.out.println("~~~~~~~~~~~~~~~~~~~~~执行完了!~~~~~~~~~~~~~~~");没有执行呢!
希望高手指点~~~~

posted on 2009-10-07 17:13 weager 阅读(638) 评论(0)  编辑  收藏 所属分类: Hibernate


只有注册用户登录后才能发表评论。


网站导航:
 
欢迎您,您是第 位来访者!