Why DynamoDB java sdk doesn't allow always auto-generated keys? -
i'd implement change history objects in dynamodb. easy way of doing specify "object id" hash , "updated time" range key. however, java sdk doesn't allow annotating keys autogenerated (changing value without annotation convenience seems work). why?
example code:
@dynamodbtable(tablename = "data") public class person { public static void main(string[] args) { amazondynamodbclient client = new amazondynamodbclient() .withendpoint("http://localhost:8000"); dynamodbmapper mapper = new dynamodbmapper(client); tableutils.deletetableifexists(client, mapper.generatedeletetablerequest(person.class)); tableutils.createtableifnotexists(client, mapper.generatecreatetablerequest(person.class) .withprovisionedthroughput(new provisionedthroughput(1l, 1l)) ); person person = new person(); person.setpersonid("abc"); mapper.save(person); mapper.save(person); tableutils.deletetableifexists(client, mapper.generatedeletetablerequest(person.class)); } @dynamodbhashkey private string personid; @dynamodbrangekey @dynamodbautogeneratedtimestamp private long updated; public string getpersonid() { return personid; } public void setpersonid(string personid) { this.personid = personid; } public long getupdated() { return updated; } public void setupdated(long updated) { this.updated = updated; } }
exception:
exception in thread "main" com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmappingexception: field com.dynamodb.testpackage.person[updated] must not have auto-generated key strategy @ com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmapperfieldmodel$builder.build(dynamodbmapperfieldmodel.java:797) @ com.amazonaws.services.dynamodbv2.datamodeling.standardmodelfactories$schemafactory.newtablemodel(standardmodelfactories.java:118) @ com.amazonaws.services.dynamodbv2.datamodeling.standardmodelfactories$schemafactory.gettablemodel(standardmodelfactories.java:86) @ com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmapper.gettablemodel(dynamodbmapper.java:401) @ com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmapper.generatecreatetablerequest(dynamodbmapper.java:2432) @ com.dynamodb.testpackage.person.main(person.java:21) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:497) @ com.intellij.rt.execution.application.appmain.main(appmain.java:147)
your use-case atypical. don't want hash , range key of object change. in fact go far it's discouraged.
in fact, dynamodb item uniquely characterized it's key (whether partition key only, or partition + range keys together) changing range key creates new item technically not update.
i'm not sure if accurately represents the reason why mixing @dynamodbautogeneratedtimestamp
, @dynamodbrangekey
not supported in sdk it's reason.
Comments
Post a Comment