79343857

Date: 2025-01-09 19:50:47
Score: 1.5
Natty:
Report link

The solution turned out to be too simple. What happened: The author of the book in the code in the Aircraft model made the id field as autogenerated (in my case, this was the problem, perhaps it was supposed to be like this, but I literally copied it from the book). After studying the forum a little, I came across a similar situation, where a person wrote that if the id comes from the other side, then a conflict of this type occurs. In particular, since my method sends a request to an external API every second, then the same object of my plane will be in different threads, and since hibernate "marks" what needs to be done with this object, it gives this ill-fated error. My solution was to add a field with the @Version annotation and remove @GeneratedValue from id .

Aircraft.java

@Id
private Long id;

@Version
private Long version;
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Version
  • User mentioned (0): @GeneratedValue
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Vlad