In one of the Rest controllers of my spring app, an instance of an entity gets loaded from the db, a field of it is changed through calling setXX method on that entity and finally it's saved back to the db .
I wonder if it is possible to update this instance in the database automatically after each call to its setXX methods. I know that performance-wise it is not ideal, but it would work for me in some cases.
Edit 1
This is a test code where I'm saving/loading the entity. I call the following helper method in a util class to save user details to the db:
public CustomUserDetails createUser(String username, String name, String description, String imageId) {
User user = new User();
user.setName(name);
user.setDescription(description);
user.setImageId(imageId);
CustomUserDetails userDetails = new CustomUserDetails(username,
DUMMY_PASSWORD, true, true, true, true,
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
userDetails.setUser(user);
userDetailsRepository.save(userDetails);
return userDetails;
}
And in the test, I get the User instance by calling getUser on the returned value from this method. I setXX some values, but it's not persisted.