hibernate如何实现部分字段更新;
比如,我新建了一个VO为person,其id=1001,更新了name属性,
数据库里存在一条id为1001的记录,现在使用merge方法把其它字段如性别、年龄等覆盖为null;
请大家给个方案吧;注:
  先load,再set就不要说啦,有没有其它的方法;

解决方案 »

  1.   

    HQL语句  就行了
    Person 是对象名 
    sex ,id 是属性名public void merge(){
         String hql = "Update Person set sex='',age='' where id=1001"
        Session session = sf.openSession();
        Query query = session.createQuery(hql); 
        Transaction tx = session.beginTransaction(); 
        try {
    query.executeUpdate();       
              tx.commit();
        } catch (Exception e) {
    tx.rollback();
        }finally{
    session.close();
        }
    }