From d5399a7677d9612418cdcdd7e95f0179f7afb4c2 Mon Sep 17 00:00:00 2001 From: raviavhad Date: Sat, 24 Jul 2021 13:45:21 +0530 Subject: [PATCH] Update UserAccountService.java Moving the call to addUserAccount method out of condition to check if violations exist. --- .../servicevalidation/service/UserAccountService.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java index 9a376fda6b..c438719d3a 100644 --- a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java +++ b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java @@ -29,15 +29,10 @@ public class UserAccountService { StringBuilder sb = new StringBuilder(); for (ConstraintViolation constraintViolation : violations) { sb.append(constraintViolation.getMessage()); - } - - dao.addUserAccount(useraccount); - + } throw new ConstraintViolationException("Error occurred: " + sb.toString(), violations); - } - - - + } + dao.addUserAccount(useraccount); return "Account for " + useraccount.getName() + " Added!"; }