Model: User
id
username
role
Controller:update(User u)
User old = User.findById(u.id);
if u.role NOT equals old.role
.......
The Problem is: User.findById(u.id); , this code return the user is not as same as PARAM u, NOT the data in database.
How can i get the DATABASE value?
Thanks for your help!
The question is really confusing. Do you mean that when you make the call
findbyId(u.id)that theold.roleis returning the value found in theuparameter and not the value found in the database?If that’s the case, maybe you can try something like this:
If you actually need to make changes to the User
uthat was detached, you will need to do this: