@Transactional public void deleteUser(long id) { User u = userDao.getUserById(id); Role adminRole = roleService.getAdminRole(); int articleCount = articleService.getArticleCountByUser(u); int adminCount = userDao.getAdminUserCount(); LOG.debug("trying to delete user " + u.getUsername()); LOG.debug("global admin count: " + adminCount); LOG.debug("is admin user: "******"number articles associated: " + articleCount); if (u.getAuthorities().contains(adminRole) && adminCount == 1) { LOG.error("cant delete last admin user"); return; } if (articleCount > 0) { LOG.error("User still has articles associated"); return; } LOG.debug("deleting user " + u.getUsername()); userDao.deleteUser(u); }