title: Google App Engine encoded key in Java
body: <p>Can someone provide some simple code about how to use an encoded key in Java for the Google app engine.  The sample code is a little bit confusing.  Suppose I have an employee class and I want the primary key to be manually constructed with a format of "name, email, phone" for example a sample key would be"James Smith,james@mycompany.com,12345678"</p>
  
  <p>With reference to the sample code</p>
  
  <pre><code>@PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
  private String encodedKey;
  
  @Persistent
  @Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
  private String keyName;
  </code></pre>
  
  <p>What values if any would I assign to <code>encodedKey</code> and <code>keyName</code>?  After various tries I'm still getting the following error:</p>
  
  <blockquote>
    <p>The primary key field is an encoded String but an unencoded value has been provided. If you want to set an unencoded value on this field you can either change its type to be an unencoded String (remove the "gae.encoded-pk" extension), change its type to be a com.google.appengine.api.datastore.Key and then set the Key's name field, or create a separate String field for the name component of your primary key and add the "gae.pk-name" extension.</p>
  </blockquote>