Module io.ebean.api
Package io.ebean

Class 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:
    Serialized Form
    • Constructor Detail

      • DuplicateKeyException

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