Search code examples
javamysqlspring-bootapisetter

Spring Boot - Avoid update DB when using setters


I would like to use the setter of my Entity without updating the database.

credentials.setPassword(null);
return credentials;

While doing this, it automatically update the DB and set the password to null. I would like to return the object credentials with password null, without updating the DB

Anyone knows how to do it?


Solution

  • You could (and maybe should) covert this Entity into a DTO before exposing it to wherever you are sending your data. That way you can fulfill whatever requirement you want (like not exposing the password) without updating your database.