]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Wed, 31 Aug 2016 14:45:52 +0000 (16:45 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 31 Aug 2016 19:53:53 +0000 (21:53 +0200)
- the user instance needs to be merged into current persience context, else some of its child entities will be persisted (inserted) again

src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java

index 5fe89f8c6d34ffecf64944a0a3011e2b800a880a..8bd661dc6999f622ad5e9d3a2098ba4d5098afba 100644 (file)
@@ -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);