现在我正在使用jpa和hibernate,当我完成getEntityManager.persist(objects)然后我会要求用户确认,例如使用用户界面继续和回滚
private List<TempCustomers> tempCustomer =new ArrayList<TempCustomers>();
@Begin(join = true)
public String migrateData() {
log.info("Mobee Migrate Customer Size :"+doTempCustomers.size());
for(DoTempCustomers tempCustomers:doTempCustomers){
try {
TempCustomers temp=new TempCustomers();
BeanUtils.copyProperties(temp, tempCustomers);
tempCustomer.add(temp);
getEntityManager().persist(temp);
}catch (Exception e) {
// TODO: handle exception
return "null";
}
}
log.info("Size........."+tempCustomer.size());
return "null";
}
@Begin(join = true)
public String updatedData(){
log.info("Size of Customers :"+tempCustomer.size());
log.info("Decision ..."+decision);
try{
if(decision.equals("Continue")){
for(TempCustomers tempCust:tempCustomer){
TempCustomers temp=new TempCustomers();
BeanUtils.copyProperties(temp, tempCust);
log.info("updated Sucessfully");
getEntityManager().getTransaction().commit();
}}else{
getEntityManager().getTransaction().rollback();
}
}
catch(Exception e){
}
}
当getEntityManager()。persist()完成时,请帮助我如何在hpa中使用hiber继续和回滚。
答案 0 :(得分:2)
提交JPA:
entityManager.getTransaction().commit();
使用JPA回滚:
entityManager.getTransaction().rollback();
在呼叫保持执行所需操作后,请调用其中一种方法。在您的情况下,entityManager
将替换为检索entityManager的调用,getEntityManager()