I'm facing strange issue last modified date is not getting updated automatically. I'm using Postgresql Version 12.3 and Springboot 2.2.4.RELEASE Here's my Entity Class
@Entity
@Table(name = "users")
@org.hibernate.annotations.Entity(
dynamicUpdate = true
)
@Data
public class Users {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(updatable = false, nullable = false)
private String userId;
private String userName;
private String userEmail;
private String userPhoneNumber;
@CreationTimestamp
@Column(updatable = false)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+05:30")
private Timestamp createdOn;
@UpdateTimestamp
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+05:30")
private Timestamp lastUpdatedOn;
}
Database Records:
createdon | lastupdatedon
2020-08-27 07:43:37.994 | 2020-08-27 07:43:37.994
2020-08-07 07:49:22.797 | 2020-08-07 07:49:22.797
2020-08-12 13:38:43.503 | 2020-08-12 13:38:43.503
You can see both createdOn and lastUpdatedOn are same. Even though the records updated frequently last modified date is not getting updated.
I'm saving record with jpa repository ex:
usersRepository.save(user);
dynamicUpdate? Just wondering. Also are you not updating something with a query somewhere (as that bypasses the listeners).