- 爱易网页
-
Java教程
- hibernate循环update()的有关问题
日期:2014-05-18 浏览次数:20755 次
hibernate循环update()的问题
.......................
Answer answer=new Answer(); //for循环外new
for(int i=0;i <answerids.length;i++){
answer=(Answer) session.load(Answer.class,new Long(answerids[i]));
answer.setStatus( "答案 ");
session.update(answer);
}
tra.commit();
.......................
//以上代码可以正常更新相应的Answer数据.
.......................
for(int i=0;i <answerids.length;i++){
Answer answer=new Answer(); //for循环内new
answer=(Answer) session.load(Answer.class,new Long(answerids[i]));
answer.setStatus( "答案 ");
session.update(answer);
}
tra.commit();
.......................
//该处只更新最后一条数据