我正在使用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";
}
本文探讨了在使用JPA与Hibernate进行数据库操作时遇到批量插入异常的情况,并提供了一种处理异常并继续保存剩余记录的方法。
1154

被折叠的 条评论
为什么被折叠?



