@Auditing with Spring Data — Concept Check
Questions on @Auditing with Spring Data. Enable @EnableJpaAuditing and annotate fields with @CreatedDate, @LastModifiedDate, @CreatedBy, @LastModifiedBy; an AuditorAware bean supplies the current user identity.
Questions in this quiz
7 questions on @Auditing with Spring Data — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer has enabled @EnableJpaAuditing but notices that the @CreatedDate field is not being populated. What could be the issue?
- AThe AuditorAware bean is not defined.
- BThe @CreatedDate annotation is used incorrectly.
- CThe entity is missing @EntityListeners(AuditingEntityListener.class).
- D@EnableJpaAuditing should not be used in a @Configuration class.
2.An entity's @LastModifiedBy field is always null after updates. What might be the cause?
- A@LastModifiedBy is not supported in Spring Data JPA.
- BThe @LastModifiedBy annotation is used incorrectly.
- CThe AuditorAware bean is not correctly implemented.
- DThe entity is missing the @MappedSuperclass annotation.
3.A developer uses Hibernate Envers for audit history but notices some fields are not tracked. Why?
- AHibernate Envers does not support tracking all fields.
- BThe fields are not part of the entity.
- C@Audited annotation is missing on the entity.
- DThe fields are annotated with @NotAudited.
4.Which annotation ensures that an entity's creation and modification timestamps are automatically populated?
- A@EnableJpaAuditing
- B@Audited
- C@EntityListeners(AuditingEntityListener.class)
- D@MappedSuperclass
5.A system user is performing batch jobs, but the @CreatedBy field is not populated. What could resolve this?
- AManually set the @CreatedBy field in the code.
- BEnable @EnableJpaAuditing in a different class.
- CUse a FallbackAuditorAware to provide a default user.
- DEnsure @CreatedBy is correctly annotated.
6.A developer claims that enabling @EnableJpaAuditing automatically tracks full audit history. Is this correct?
- AYes, it tracks all changes by default.
- BNo, it only tracks the latest state.
- CNo, it requires additional configuration with Hibernate Envers.
- DYes, but only for entities with @Audited.
7.Why might the @CreatedBy field remain empty even when a user is authenticated?
- AThe AuditorAware bean returns an empty Optional.
- BThe entity is not annotated with @Entity.
- C@CreatedBy is not supported for authenticated users.
- D@CreatedBy is incorrectly placed on a non-entity field.