Skip to content

Auditing does not work with @Modifying query #970

Closed
@mcimbora

Description

@mcimbora

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions