Is there a way to configure an @UpdateTimestamp field so it won’t get populated when the entity gets created but only when the entity gets updated?
Here is what I’m doing in this addUser operation,
@Entity
@Table(schema = "alpha", name = "user_profile")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id_sequence_generator")
@SequenceGenerator(name = "user_id_sequence_generator", schema = "alpha", allocationSize = 1, sequenceName = "user_id_seq")
private Integer id;
private String login;
private String password;
@CreationTimestamp
private LocalDateTime created;
@UpdateTimestamp
private LocalDateTime modified;
User newUser = new User();
newUser.setLogin(addUserInput.getLogin());
newUser.setPassword(md5DigestAsHex(addUserInput.getPassword().getBytes()));
userRepository.save(newUser);
entityManager.flush();
UserOutputTO addUserOutput = new UserOutputTO();
addUserOutput.setId(newUser.getId());
addUserOutput.setLogin(addUserInput.getLogin());
addUserOutput.setCreated(newUser.getCreated());
addUserOutput.setModified(newUser.getModified());
return addUserOutput;