日期:2014-05-20 浏览次数:20884 次
sql = String.format("select * from %s where dg_id=%d and id=%d",sumo.getTableName(),sumo.getDgId(),sumo.getTraitId()); Session session = sessionFactory.openSession(); Transaction tx = null; try { //开启事物 tx = session.beginTransaction(); //获取修改的那条记录 List<TraitStrTrees> list = session.createSQLQuery(sql).addEntity(TraitStrTrees.class).list(); if(list.size()==0){ return ; } TraitStrTrees tst = list.get(0); List<Integer> intList = SUUtil.parsingBinary(tst.getArticles()); if(intList.size()==0){ //说明数据有误,但也可以直接添加 }else if(intList.size()==1){ //直接修改 tst.setTrait_value(sumo.getTraitItemValue()); session.update(tst); }else{ //删除后再修改,最后添加一条记录 } //提交事物 tx.commit(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); }