Save() returns the saved object with wrong attributes, the attribute "price" should return a rounded value.
Let's say I have the following table:
CREATE TABLE OBJ(
ID INT PRIMARY KEY AUTO_INCREMENT,
NAME VARCHAR(30) NOT NULL,
DESCRIPTION VARCHAR(200) NOT NULL,
PRICE DECIMAL(10,2) NOT NULL,
);
If I do:
Obj newobj = new Obj("obj name", "brief description", 12.555);
repository.save(newObj);
Looking into the database, the object was saved correctly, so the price saved is 12.56 but method save() has returned the saved object with price = 12.555. Could this behavior be a bug?
Could this behaviour be a bug?
No. This is the expected behaviour. The only value that gets returned after it was modified by the database is the id.
If you want such values to get updated you need to require from the database. When doing so you'll have to makes sure to do so without the entity being in the persistence context, to avoid the 1st level cache to interfere with your attempt to reload the entity.