Skip to content

Commit

Permalink
Add conditional logic to UserRepository save method
Browse files Browse the repository at this point in the history
The save method in UserRepository.java has been enhanced. If a User object's UUID is not null, then the User is merged to ensure an update takes place, else it's persisted to create a new user record. This preserves data integrity by avoiding possible unintentional user overwrites.
  • Loading branch information
Gcolon021 committed Feb 1, 2024
1 parent 3e5b7eb commit 1741cab
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ public User createOpenAccessUser(Role openAccessRole) {
* @param user the user to save
*/
public void save(User user) {
em().merge(user);
// if user exists update, else create
if (user.getUuid() != null) {
em().merge(user);
} else {
em().persist(user);
}
}

}

0 comments on commit 1741cab

Please sign in to comment.