Class DuplicateKeyException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
jakarta.persistence.PersistenceException
io.ebean.DataIntegrityException
io.ebean.DuplicateKeyException
All Implemented Interfaces:
Serializable

public class DuplicateKeyException extends DataIntegrityException
Thrown when a duplicate is attempted on a unique constraint.

In terms of catching this exception with the view of continuing processing using the same transaction look to use Transaction.rollbackAndContinue().


  try (Transaction txn = database.beginTransaction()) {

    try {
      ...
      database.save(bean);
      database.flush();
    } catch (DuplicateKeyException e) {
      // carry on processing using the transaction
      txn.rollbackAndContinue();
      ...
    }

    txn.commit();
  }

See Also:
  • Constructor Details

    • DuplicateKeyException

      public DuplicateKeyException(String message, Throwable cause)
      Create with a message and cause.