From: Roland Häder Date: Wed, 31 Aug 2016 14:45:52 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bf6b278f7b14de659a2bb7dde426692640afd30e;p=jjobs-ejb.git Please cherry-pick: - the user instance needs to be merged into current persience context, else some of its child entities will be persisted (inserted) again --- diff --git a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java index 982da11..cdd34a1 100644 --- a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java @@ -645,13 +645,15 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes User managedUser = this.updateUserData(user); // Create history entry - PasswordHistory entry = new UserPasswordHistory(); + PasswordHistory entry = new UserPasswordHistory(managedUser.getUserEncryptedPassword(), managedUser); - // Set all data here to avoid user instance become detached again - entry.setUserPasswordHistoryPasswordHash(managedUser.getUserEncryptedPassword()); - entry.setUserPasswordHistoryUser(this.getManagedUser(user)); + // Set created timestamp entry.setUserPasswordHistoryCreated(new GregorianCalendar()); + // Merge user to make sure it is not re-persisted + User mergedUser = this.getEntityManager().merge(managedUser); + entry.setUserPasswordHistoryUser(mergedUser); + // Persist it this.getEntityManager().persist(entry);