I am writing an app with Spring Boot + JPA, using a Postgres database. I have a User Entity and I am trying to get a timestamp when the user record is saved and/or modified.
The AuditingEntityListener methods are called in the @PrePersist
and @PreUpdate
phase.
This means they are called just before the insert or update SQL statements are executed.
Read more about JPA events in the Hibernate doc: https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#events-jpa-callbacks
Unit Tests
When using in Tests you have to enable auditing as well on the test
@DataJpaTest
@RunWith(SpringRunner.class)
@EnableJpaAuditing
public class EntityListenerTest {