0

Im having a problem with a major data migration that can be configured by the user, lets say it goes like this:

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();
}

My problem is that when the IndexDuplicityException is throwed, any of the future transactions are ignored, giving me this exception

PSQLException: current transaction is aborted, commands ignored until end of transaction block

Isnt there a way to my transaction allow failed excecuted statements and not abort the whole transaction?

Thanks.

leomcpugo
  • 35
  • 8
  • Does Postgres support exception tables where constraint violations are written to ? This might suppress the exception which marks the transaction as rollback only. – Nicholas Nov 05 '14 at 11:38
  • @Nicholas could you explain a little more? – leomcpugo Nov 06 '14 at 15:42

1 Answers1

0

Try to rollback the transaction and start a new one on IndexDuplicityException:

   }catch(IndexDuplicityException ex) {
    inserted = false;       
    daoManager.RollBack();
    daoManager.beginTransaction();
   }
rafalopez79
  • 2,046
  • 4
  • 27
  • 23