spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Auditing does not work with @Modifying query

Open mcimbora opened this issue 4 years ago • 1 comments

Hi,

Thanks for the amazing project. I'm using version 2.4.5 and I've observed an issue with auditing (https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#jdbc.auditing).

Let's consider an entity with the following attributes:

@LastModifiedDate
private LocalDateTime lastModifiedAt;

@LastModifiedBy
private Long lastModifiedById;

private boolean locked;

If I update the entity using CrudRepository.save, all is good and I can see the corresponding auditing DB attributes got updated. Configured auditorProvider got invoked (verified using debugger).

The problem I face occurs when I use @Modifying + @Query to update the entity.

@Modifying
@Query("update MY_ENTITY set locked = false where id = :entityId")
void unlockMyEntity(Long entityId)

Auditing DB attributes are not updated - judging by auditorProvider never invoked in this case (verified using debugger), is this combo unsupported? If this is the case, it would be good to include this piece of information in the documentation to avoid confusion.

Regards, Matej

mcimbora avatar Apr 28 '21 10:04 mcimbora

You are correct this is not supported and we should improve the documentation to make this clear.

schauder avatar May 03 '21 09:05 schauder