List of usage examples for org.springframework.dao DuplicateKeyException getCause
public synchronized Throwable getCause()
From source file:org.jutge.joc.porra.service.AccountService.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private void handleDuplicatekeyException(final DuplicateKeyException exception) throws SignupException { final Throwable cause = exception.getCause(); if (cause instanceof MongoException) { final Locale locale = LocaleContextHolder.getLocale(); final MongoException mongoException = (MongoException) cause; final String exceptionMessage = mongoException.getMessage(); List errorMessages = new ArrayList(); if (exceptionMessage.indexOf("account.$_id_") != -1) { final String message = this.messageSource.getMessage("exception.accountNameTaken", null, locale); final MessageBox messageBox = new MessageBox("accountNameTaken", message, new ArrayList<String>()); errorMessages.add(messageBox); } else if (exceptionMessage.indexOf("account.$email") != -1) { final String message = this.messageSource.getMessage("exception.accountEmailTaken", null, locale); final MessageBox messageBox = new MessageBox("accountEmailTaken", message, new ArrayList<String>()); errorMessages.add(messageBox); }// ww w .ja v a 2s . c o m throw new SignupException(errorMessages); } else { this.logger.error(exception.getMessage()); } }