Example usage for org.springframework.dao DataAccessException getMostSpecificCause

List of usage examples for org.springframework.dao DataAccessException getMostSpecificCause

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException getMostSpecificCause.

Prototype

public Throwable getMostSpecificCause() 

Source Link

Document

Retrieve the most specific cause of this exception, that is, either the innermost cause (root cause) or this exception itself.

Usage

From source file:org.mifosplatform.portfolio.savings.service.SavingsProductWritePlatformServiceJpaRepositoryImpl.java

private void handleDataIntegrityIssues(final JsonCommand command, final DataAccessException dae) {

    final Throwable realCause = dae.getMostSpecificCause();
    if (realCause.getMessage().contains("sp_unq_name")) {

        final String name = command.stringValueOfParameterNamed("name");
        throw new PlatformDataIntegrityException("error.msg.product.savings.duplicate.name",
                "Savings product with name `" + name + "` already exists", "name", name);
    } else if (realCause.getMessage().contains("sp_unq_short_name")) {

        final String shortName = command.stringValueOfParameterNamed("shortName");
        throw new PlatformDataIntegrityException("error.msg.product.savings.duplicate.short.name",
                "Savings product with short name `" + shortName + "` already exists", "shortName", shortName);
    }//from   ww w  .  ja v a 2 s . com

    logAsErrorUnexpectedDataIntegrityException(dae);
    throw new PlatformDataIntegrityException("error.msg.savingsproduct.unknown.data.integrity.issue",
            "Unknown data integrity issue with resource.");
}