我正在使用jpa与hibernate我想在数据库中插入100条记录,假设我在第50条记录插入中得到异常JDBC批量更新我需要处理异常,我需要将剩余记录保存到DB.
码:
private List tempCustomer =new ArrayList();
public String migrateCustomers() {
TempCustomers temp = null;
for(DoTempCustomers tempCustomers:doTempCustomers){
try {
temp=new TempCustomers();
BeanUtils.copyProperties(temp, tempCustomers);
tempCustomer.add(temp);
entityManager.persist(temp);
}catch (Exception e) {
tempCustomer.add(temp);
entityManager.persist(temp);
log.info("Exception ..."+e);
return "null";
}
}
return "null";
}