I have a profile update request in my ProfileController, but when I try to send this update request in my MineCraft plugin, I get this error:
org.hibernate.id.IdentifierGenerationException: Identifier of entity 'net.lydecube.galapy.model.profile.Profile' must be manually assigned before calling 'persist()'
ProfileController#update:
@PutMapping
public ResponseEntity<?> updateProfile(@RequestBody UpdateProfileDto updateProfileDto) {
// We create updating profile by using modelMapper, and we check if it exists
val profile = modelMapper.map(updateProfileDto, Profile.class);
if (profileService.existsById(updateProfileDto.getId())) {
// We check and update ipHistory
if (!ipHistoryService.exists(updateProfileDto.getId(), updateProfileDto.getLastIp())) {
IpHistory ipHistory = new IpHistory();
ipHistory.setProfile(profile);
ipHistory.setId(updateProfileDto.getId());
ipHistory.setAddress(updateProfileDto.getLastIp());
profile.setLastIp(ipHistory);
IpHistory oldIpHistory = ipHistoryService.findByProfileId(updateProfileDto.getId()).get();
oldIpHistory.setLastUsed(new Timestamp(System.currentTimeMillis()));
ipHistoryService.save(ipHistory);
ipHistoryService.save(oldIpHistory);
}
// We save updating profile, and we return it
profileService.update(profile);
return ResponseEntity.ok(profileMapper.mapProfile(profile));
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Profile was not found.");
}
}```