John Britto
John Britto

Reputation: 457

How to fetch the data in datastore with a key

I have a problem in fetching the data from the datastore. I have the key for the entity but using that key i am able to fetch the ID, Kind name, but not the properties

here is the code i tried.

        for(int j=0;j<mem.size();j++) 
        {
            Key key=mem.get(j);
            Entity con=new Entity(key);

            System.out.println("Kind Name = "+con.getKind() );

            System.out.println("Key = "+con.getKey() );
            System.out.println("ID = "+con.getKey().getId() );
            System.out.println("first name="+con.getProperty("FirstName") );
        }

the getproperty() method does not fetch the data

thanks in advance.

Upvotes: 0

Views: 183

Answers (1)

Dan Sanderson
Dan Sanderson

Reputation: 2111

Constructing a new Entity with the given key does not fetch the entity from the datastore, it creates a new entity in memory with the same key. To get the entity, you must call datastore.get(key) (where datastore is the DatastoreService that you create with DatastoreServiceFactory.getDatastoreService()).

Upvotes: 2

Related Questions