【发布时间】:2014-12-31 19:15:36
【问题描述】:
我遇到了可由用户配置的主要数据迁移问题,可以说是这样的:
try {
daoManager.beginTransaction();
for (Entity node : nodeList) {
boolean inserted;
if (migrationConfig.canInsert()) {
try {
inserted = daoManager.getDaoEntity().insert(node);
}
catch(IndexDuplicityException ex) {
inserted = false;
//I want the transaction to continues when this Exceptions is
//throwed
}
}
if (migrationConfig.canUpdate() && !inserted) {
modificoEntidad = daoManager.getDaoEntity().update(node);
}
}
//Later
if (//Business Logic) {
throw new MustRollBackTransaction();
}
daoManager.commitTransaction();
} catch (MustRollBackTransaction ex) {
daoManager.RollBack();
}
我的问题是当 IndexDuplicityException 被抛出时,任何未来的交易都会被忽略,给我这个异常
PSQLException: 当前事务被中止,命令被忽略直到 交易区块结束
有没有办法让我的交易允许失败的执行语句而不中止整个交易?
谢谢。
【问题讨论】:
-
Postgres 是否支持写入约束违规的异常表?这可能会抑制将事务标记为仅回滚的异常。
-
@Nicholas 你能解释一下吗?
标签: java sql postgresql transactions rollback