How to query DynamoDB based on Partition Key and Sort Key [Java]? -


i new dynamodb , wanted know how can query on table in dynamodb hashkey , sortkey.

i have table named items. it`s schema is

1. product (partition key of type string) 2. id (sort key of type int) 3. date ( attribute of type string) 

my query getting items having product = 10 is

items = new items(); it.setproduct("apple");  dynamodbqueryexpression<items> queryexpression = new dynamodbqueryexpression<items>()             .withhashkeyvalues(it);   list<items> itemlist = mapper.query(items.class, queryexpression); 

but, want items having product = "apple" , id = 100.

i can write query in java dynamodb .

in order data dynamodb using partition key , sort key. can use load method present on dynamodbmapper class.

dynamodbmapper mapper = new dynamodbmapper(dynamodbclient); string product = "ball"; integer id = 1; item itemobj = mapper.load(items.class, product, id); 

model class i.e. in case item class:-

you should have item class defined proper annotation hash , range key.

@dynamodbtable(tablename = "items") public class item {      private string product;     private integer id;      @dynamodbhashkey(attributename = "product")     public string getproduct() {         return autoid;     }        @dynamodbrangekey(attributename = "id")     public string getid() {         return id;     }            }    

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -