title: How to select a single Entity by key (low level java datastore API)
body: <p>I'm a bit confused on how to create a "Key" object to select exactly 1 row of my Entity ("Customer").</p>
  
  <p>My code :</p>
  
  <pre><code>Query query = new Query("Customer");
  // **** how do I have to create this key ???
  Key key = KeyFactory.createKey("Customer", 1);
  // ****
  FilterPredicate keyFilter =  new FilterPredicate(Entity.KEY_RESERVED_PROPERTY,       FilterOperator.EQUAL, key);
  query.setFilter(keyFilter);
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  PreparedQuery pq = datastore.prepare(query);
  Entity customer = pq.asSingleEntity();
  if  (! (customer == null)) {
      log.info("OK !");
  }
  else {
      log.info("no customer found");
  }
  </code></pre>
  
  <p>My result is always : "no customer found".</p>
  
  <p>With the datastore viewer (I'm working locally) I can see 3 rows :</p>
  
  <ul>
  <li>id/name = 1   email = "your email" name = "your name"</li>
  <li>id/name = 2   email = "your email" name = "your name"</li>
  <li>id/name = 3   email = "your email" name = "your name"</li>
  </ul>
  
  <p>I want to select customer with id/name=1.
  I've tried :
  KeyFactory.createKey("Customer", 1);
  and
  KeyFactory.createKey("Customer", "your name");</p>
  
  <p>but with no success.</p>
  
  <p>When I do programmatically a search (asList) on "Customer" and I print the keys' values I see :</p>
  
  <ul>
  <li>row 1 key = Customer("your name")/Customer(1)</li>
  <li>row 2 key = Customer("your name")/Customer(2)</li>
  <li>row 3 key = Customer("your name")/Customer(3)</li>
  </ul>
  
  <p>The printable values of the keys are in the format : "Entity(name)/Entity(id/name)"</p>
  
  <p>How can I create such key values in my code ?
  On the javadoc I see only :</p>
  
  <ul>
  <li>createKey("kind", id)</li>
  <li>createKey("kind", "name")</li>
  </ul>
  
  <p>The other methods require an ancestor, I've not created an ancestor .... 
  This is the code that I've executed to created the 3 rows (it has been executed 3 times) :</p>
  
  <pre><code>Key customerKey = KeyFactory.createKey("Customer", "your name");
  Entity customer = new Entity("Customer", customerKey);
  customer.setProperty("name", "your name");
  customer.setProperty("email", "your email");
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  datastore.put(customer);
  </code></pre>
  
  <p>Thanks in advance !</p>
  
  <p>Regards</p>
  
  <p>Max</p>
  
  <p><strong>In other words, how do create a Key whose "toString" gives the following result ?</strong></p>
  
  <ul>
  <li>Code : log.info("customer KeyFactory.keyToString =  "+KeyFactory.keyToString(key));</li>
  <li>Output : INFO: customer KeyFactory.keyToString = Customer("your name")/Customer(1)</li>
  </ul>