}
// Call other method
- User updatedUser = this.updateUserData(user);
+ User managedUser = this.updateUserData(user);
// Create history entry
- PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), updatedUser);
+ PasswordHistory entry = new UserPasswordHistory();
- // Set created timestamp
+ // Set all data here to avoid user instance become detached again
+ entry.setUserPasswordHistoryPasswordHash(managedUser.getUserEncryptedPassword());
+ entry.setUserPasswordHistoryUser(managedUser);
entry.setUserPasswordHistoryCreated(new GregorianCalendar());
// Persist it
try {
// Create email address and set
- emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
+ emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress());
} catch (final AddressException ex) {
// Throw again
throw new EJBException(ex);