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

Annotation @EnableDynamoDBAuditing is not working properly

Open manascimento opened this issue 7 years ago • 4 comments

Expected Behavior

Persist the current logged user in the Dynamodb table.

Actual Behavior

It is not possible to get the user inside the class annotated with @DynamoDBTable or @DynamoDBDocument.

Steps to Reproduce the Problem

  1. I annotated my DynamodbConfig (@Configuration) class with @EnableDynamoDBAuditing(auditorAwareRef = "auditorProvider", modifyOnCreate = true, setDates = true);
  2. I created a method (named auditorProvider()) and annotated it with @Bean. This method returns org.springframework.data.domain.AuditorAware;
  3. I tried to save my document (repository.save - DynamoDBCrudRepository) and no data related to user and dates are saved in the Dynamodb table.

Specifications

  • Spring Data DynamoDB Version: 5.0.2
  • Spring Data Version: 2.0.8.RELEASE
  • AWS SDK Version: 1.11.336
  • Java Version: 1.8
  • Platform Details: Linux (Ubuntu)

manascimento avatar Jul 17 '18 17:07 manascimento

May related to #169

derjust avatar Jul 18 '18 05:07 derjust

@derjust,

Just a couple more information to help in this issue.

I missed some annotations (for Dynamodb) to use the @EnableDynamoDBAuditing properly such as:

@CreatedBy @LastModifiedBy @CreatedDate @LastModifiedDate

Of course, it is impossible to use those annotations, because they are available only for Entities (@Entity).

I found an annotation (@DynamoDBAutoGeneratedTimestamp) in AWS SDK that I can substitute @CreatedDate and @LastModifiedDate. I only need to define DynamoDBAutoGenerateStrategy (CREATE or ALWAYS).

Unfortunately, I can't use org.springframework.data.annotation.CreatedBy and org.springframework.data.annotation.LastModifiedBy and AWS SDK does not provided any annotations.

I think that the issue #169 is different from this one, because the 169's author is trying to use DynamoDB Auditing with Entities. I mean that he is assuming that DynamoDB Auditing works, and I guess that DynamoDB Auditing is not working.

Thanks.

manascimento avatar Jul 18 '18 22:07 manascimento

Is that to say that @EnableDynamoDBAuditing currently doesn't actually do anything in any circumstance?

fireboy1919 avatar Jul 27 '18 21:07 fireboy1919

After more inspection of the code, I can see that this does actually add "modifiedBy" and "modifiedDate" just fine as long as you have an AuditibleAware bean defined. It doesn't seem to add created date or created by currently (at least, I couldn't get that to work).

Those annotations are in spring-commons-data, which is a part of spring data, so they're definitely not only available for entities.

fireboy1919 avatar Aug 27 '18 16:08 fireboy1919