{"record":{"id":"a0a45dff7d3f8d4c","repo":"elunez/eladmin","slug":"user-with-email-existed","errorCode":null,"errorMessage":"User with email {} existed","messagePattern":"User with email (.+?) existed","errorType":"exception","errorClass":"EntityExistException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java","lineNumber":92,"sourceCode":"    public UserDto findById(long id) {\n        String key = CacheKey.USER_ID + id;\n        User user = redisUtils.get(key, User.class);\n        if (user == null) {\n            user = userRepository.findById(id).orElseGet(User::new);\n            ValidationUtil.isNull(user.getId(), \"User\", \"id\", id);\n            redisUtils.set(key, user, 1, TimeUnit.DAYS);\n        }\n        return userMapper.toDto(user);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void create(User resources) {\n        if (userRepository.findByUsername(resources.getUsername()) != null) {\n            throw new EntityExistException(User.class, \"username\", resources.getUsername());\n        }\n        if (userRepository.findByEmail(resources.getEmail()) != null) {\n            throw new EntityExistException(User.class, \"email\", resources.getEmail());\n        }\n        if (userRepository.findByPhone(resources.getPhone()) != null) {\n            throw new EntityExistException(User.class, \"phone\", resources.getPhone());\n        }\n        resources.setIsAdmin(false);\n        userRepository.save(resources);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void update(User resources) throws Exception {\n        User user = userRepository.findById(resources.getId()).orElseGet(User::new);\n        ValidationUtil.isNull(user.getId(), \"User\", \"id\", resources.getId());\n        User user1 = userRepository.findByUsername(resources.getUsername());\n        User user2 = userRepository.findByEmail(resources.getEmail());\n        User user3 = userRepository.findByPhone(resources.getPhone());\n        if (user1 != null && !user.getId().equals(user1.getId())) {\n            throw new EntityExistException(User.class, \"username\", resources.getUsername());","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java#L74-L110","documentation":"EntityExistException thrown in UserServiceImpl.create when the email is already registered. The email is treated as globally unique across users; findByEmail returning any row aborts creation before the phone check runs.","triggerScenarios":"POST /api/users with an email address already present on another user account (corporate shared mailbox reused for two accounts).","commonSituations":"Creating both a personal and a service account with the same company email; importing HR data where one person had two records; password-reset flows that rely on unique email.","solutions":["Use a unique email per account (e.g. alias like user+ops@company.com for service accounts).","Free the email first by clearing/changing it on the existing account.","Validate email uniqueness client-side against the user list before submitting."],"exampleFix":"// before\nuser.setEmail(\"shared@company.com\"); // already registered\n\n// after\nuser.setEmail(\"ops-bot@company.com\");","handlingStrategy":"validation","validationCode":"if (userRepository.findByEmail(form.email) != null) { errors.email = '邮箱已被注册'; return; }","typeGuard":"const isUnique = (v: string, list: {email:string}[]) => !list.some(u => u.email === v);","tryCatchPattern":"catch (EntityExistException e) { if (e.getMessage().startsWith(\"User with email\")) errors.email = '邮箱已被占用'; }","preventionTips":["One account per email — use plus-aliases for service accounts","Validate email server-side pattern plus uniqueness","Deduplicate emails in HR imports"],"tags":["eladmin","user","duplicate","email","create"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}