I have a simple controller method, where I create a new object Car
and then set its name to Audi
:
@GetMapping(value = "/resource")
public ResponseEntity visit() {
Car car = carRepo.save(new Car("VolksWagen")); // Car should be managed now?
car.setName("Audi"); // <-- has no effect on database state
return ResponseEntity.ok().build();
}
In the database, it never becomes an Audi
, but stays a VolksWagen
.
Why does this happen? Shouldn't the newly created Car
be in managed state for the persistence context?
Note: It works if I add the @Transactional
annotation. I thought it would be enough if OSIV is enabled. What am I misunderstanding about OSIV and @Transactional
?