【发布时间】:2020-12-14 06:53:44
【问题描述】:
我有一个关于注释的问题 我的班级:
@Override
@Transactional
public void process() {
. . .
send(persons);
}
public void send(List<person> persons) {
. . .
// person list size 1.000.0000
for(...){
update(persons); --> 1000, 1000 sending for loop
}
}
public void update(List<person> persons){
...
List<person> errorPersons;
...
persons.forEach(person-> {
person.setName("Google - " + person.getName());
});
persons.removeAll(errorPersons);
getSession().getTransaction().commit(); //--|
getSession().beginTransaction(); //--| > is works!
getSession().clear(); //--|
send(persons); //recursive
}
它的工作原理如下。如何使用注释做到这一点?
getSession().getTransaction().commit(); //--|
getSession().beginTransaction(); //--| > is works!
getSession().clear();
我尝试了一些方法,但都不起作用,您能帮忙解决这个问题吗?
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void update(List<person> persons){
getSession().getTransaction().commit(); //--> Not Working
}
@Transactional(propagation = Propagation.REQUIRES)
public void update(List<person> persons){
getSession().getTransaction().commit(); //--> Not Working
}
我只是想做,怎么做这个更优化?
【问题讨论】:
标签: java hibernate transactions annotations