Home > Net >  jpa save() fails without any error message
jpa save() fails without any error message

Time:01-03

When I tried to use the save() method of jpa to save the entity today, I found that the save was not successful, and there was no error message

@Override
//@Transactional
public ResponseEntity<Object> createAdminUser(CreateUpdateAdminUserDto createUpdateAdminUserDto) {

    AdminUser adminUser = createAdminUserMapper.toEntity(createUpdateAdminUserDto);

    System.out.println("-----");
    System.out.println(adminUser);
    adminUserRepository.save(adminUser);

    return ResponseResult.ok(HttpBody.build(MessageCode.SUCCESS, new HashMap<>()));
}

This is the result of the console output

enter image description here

I have used debug to see the breakpoints, but the release of springboot ended when the save() was executed, and the return line was not executed. It was normal for me to use jpa save() before. I would like to ask if there is any way to solve it or let it go Error messages can be generated, thanks

CodePudding user response:

first, you have to Autowire your repository using @Autowired annotation. Like this

@Override //@Transactional public ResponseEntity createAdminUser(CreateUpdateAdminUserDto createUpdateAdminUserDto) {

@Autowired
private AdminRepository adminRepository;

AdminUser adminUser = createAdminUserMapper.toEntity(createUpdateAdminUserDto);

System.out.println("-----");
System.out.println(adminUser);
adminUserRepository.save(adminUser);

return ResponseResult.ok(HttpBody.build(MessageCode.SUCCESS, new HashMap<>()));

}

CodePudding user response:

I think you should give more detail about your code. For example how you wrote repository class, service class or the shape of AdminUser entity for exact answer.

  • Related