Swapnil Chaudhari
Swapnil Chaudhari

Reputation: 542

How to use default id generated in app engine

I am new to app engine development. I am using Java for development. Whenever a new entity is added it shows an "id=5076324926357504", which wasn't part of entity. I have few queries about this:

  1. Is this unique in the entire table?
  2. How can use it as primary key?

Upvotes: 0

Views: 72

Answers (2)

Sachin Kariyattin
Sachin Kariyattin

Reputation: 560

You can indirectly use it as a primary key by making one of your attributes in the entity, as ID. For example ,In the below code slno which is also an attribute of kind "Registration" is used as an entity id.

Key dbkey=KeyFactory.createKey("Registration", slno); Entity E1= new Entity("Registration",dbkey); E1.setProperty("Slno",slno); E1.setProperty("Name",name);

Now,whenever a new entity is added its slno attribute acts a unique identifier i.e. only one entity containing unique slno can be added. If same slno is given twice , instead of creating a new entity ,the previous entity will be overwritten.

Upvotes: 2

David Cifuentes
David Cifuentes

Reputation: 564

  1. Yes, if it is autogenerated that ID will be unique to the kind (table). If you assign it manually you'll need to make sure is unique in your logic.
  2. You can call the method getId for the entity to get it

Take a look at: https://developers.google.com/appengine/docs/java/datastore/entities#Java_Kinds_and_identifiers

Upvotes: 0

Related Questions