如何判断hibernate从数据库中获取的对象是否为空,若为空,改怎么处理?

解决方案 »

  1.   

    return null;
    你想干什么,目的是什么?
      

  2.   

    直接判断是不是null就可以了。至于为空的处理要看你的需求了。你可以出message或者抛异常
      

  3.   

    我写了个dao方法,插入数据库使用try..catch抛出异常会出现三个错误异常,其中一个是空指针异常,我想捕获它然后返回空值这样可以吗?
      

  4.   

    public void save(<T> transientInstance) {
    log.debug("saving instance");
    try {
    getHibernateTemplate().save(transientInstance);
    log.debug("save successful");
    } catch (RuntimeException re) {
    log.error("save failed", re);
    throw re;
    }
    }
      

  5.   

    if(object==null)
       return null;
    object是你获取的对象