From 3f2b53b952bea5d15c44682baedd456bd4fd83f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 31 Aug 2016 16:45:52 +0200 Subject: [PATCH] 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 --- .../jusercore/model/user/PizzaUserSessionBean.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index 5fe89f8..8bd661d 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -645,13 +645,15 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS 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); -- 2.39.5