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();
.......................
//该处只更新最后一条数据
Answer answer=new Answer();
这个放在for()循环里面和外面,为什么会产生2种不同的效果,我迷惑不解,请大家详细说说............谢谢!
[解决办法]
倒觉得应该是一样的结果
[解决办法]
只有在清除缓存的时候才执行hql语句
看看hibernate缓存
[解决办法]
for(int i=0;i <answerids.length;i++){
Answer answer=new Answer(); //for
answer=(Answer) session.load(Answer.class,new Long(answerids[i]));
answer.setStatus( "答案 ");
session.update(answer);
}
tra.commit();