Skip to content

DynamoDbAutoGeneratedTimeStampAttribute get methods are not working as expected as v1 #6183

Open
@adarshk007

Description

@adarshk007

Describe the bug

In aws sdk v1 :

@DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.CREATE)

Above annotation was there to create auto generated time field.

In aws sdk v2 replaced with below code:

@DynamoDbUpdateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS)
@DynamoDbAutoGeneratedTimeStampAttribute
public Instant getCreatedOn() { return createdOn;}

Also added the below extension in Enhanced Client:

.extensions(AutoGeneratedTimestampRecordExtension.create())

In v1, the getCreatedOn() method allowed direct access to creation timestamps from the entity.

However, in v2, we've encountered an issue where getCreatedOn() consistently returns null after using TransactionWriteItems to persist data, even though the data is correctly stored in the database.

This currently requires an extra get operation to fetch the createdOn value, which impacts performance.

My understanding (Might be wrong) : Previously, the createdOn value appeared to be generated during entity creation. However, it now seems to be generated either during the insertion process or at the client level.

While we have a method for manually retrieving this data, we believe this represents a regression, as core functionalities from v1 should ideally be preserved and function as expected in v2.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

when a user performs .getCreatedOn() using the entity mapper it should return the time instead of null

Current Behavior

returning null on using enitity.getCreatedOn() [here entity is User Schema]

Reproduction Steps

Create an entity User:

@DynamoDbBean
public class User {

  private Instant createdOn;

  @DynamoDbUpdateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS)
  @DynamoDbAutoGeneratedTimeStampAttribute
  public Instant getCreatedOn() { return createdOn;}
}


User u = User.builder().build();

TransactPutItemEnhancedRequest<User> req =  TransactPutItemEnhancedRequest.builder(User.class).item(u).build();

enhancedDbClient.transactWriteItems(k -> k.addPutItem(table, req));

Issue is when u.getCreatedOn() will give error because of null but in v1 it was working fine.

The current work around is manually add the value Or I am missing something.

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

2.31.41

JDK version used

java 17.02.12

Operating System and version

Sequoia 15.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions