google app engine - Read from datastore not consistent -
i new google app engine, trying sample code , stuck :(
below code:
datastore = datastoreservicefactory.getdatastoreservice();
transaction txn = datastore.begintransaction(); entity oset = new entity("set", "set1"); datastore.put(oset); entity oitem1 = new entity("item", "item1", oset.getkey()); oitem1.setproperty("qty", "two"); datastore.put(oitem1); entity oitem2 = new entity("item", "item2", oset.getkey()); oitem2.setproperty("qty", "five"); datastore.put(oitem2); query query = new query("item").setancestor(oset.getkey()); list<entity> oitems = datastore.prepare(query).aslist(fetchoptions.builder.withlimit(50)); for(entity : oitems) { system.out.println("item qty: " + i.getproperty("qty")); } txn.commit();
i trying create 2 "item" entities 1 property "qty". these 2 "item" entities descendants of entity "set". not able retrieve "item" entities back. wrong query?
you need put txn.commit(); after datastore.put(oitem2); ensure write operation completed, after running query (with or without separate transaction) fetch correct results
hope helps.
Comments
Post a Comment