0

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?

user3476509
  • 171
  • 10
  • You should be able to detach the processed entity from the current session, follow this answer: https://stackoverflow.com/a/26812963/14056755 – Marcin Rzepecki Apr 12 '21 at 16:51

2 Answers2

1

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.

Chris Savory
  • 2,597
  • 1
  • 17
  • 27
0

if the entity is still associated with the session then there is a possibility of updating the database table when there is a change in the entity params. refer this post for more details.

make sure that the entity detached and then make the changes or use DTO with the information you want to pass on to UI or destination.

krishna thota
  • 182
  • 1
  • 3
  • 8