79475634

Date: 2025-02-28 13:18:24
Score: 1
Natty:
Report link

I think this is what happened in your flow:

  1. Hibernate loads the User from the database, which has a UserRole with id = 2ee569d5-91dc-4eb9-82f7-7ce7d76b158a.
  2. A new UserDto is sent, containing a UserRole with id = 150179b8-a235-452f-aaeb-a536174a0f94.
  3. modelMapper.map(userDto, user) overwrites the entire UserRole object in User, replacing it with a new instance from UserDto.
  4. Hibernate detects that the UserRole associated with User has changed from the old id to a new id, but the identifier of a managed entity cannot be changed → Hibernate throws an error:
Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: le dat