title: GAE Datastore generate String key with JPA
body: <p>Since it isn't possible to use only Long Ids I am trying to use the generated String keys. I have three Classes <code>User</code>, <code>Topic</code>, <code>Comments</code> with <code>User</code> - 1:n - <code>Topic</code> - 1:n -<code>Comments</code>. </p>
  
  <p><strong>Class Comment:</strong></p>
  
  <pre><code>@Entity
  public class Comment implements Serializable{
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
      private String key;
      @ManyToOne
      private User author;
      @ManyToOne
      private Topic topic;
  </code></pre>
  
  <p><strong>Class User:</strong></p>
  
  <pre><code>@Entity
  public class User implements Serializable{
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
      private String key;
  
      @Unique
      private String username;
  </code></pre>
  
  <p><strong>Class Topic:</strong></p>
  
  <pre><code>@Entity
  public class Topic implements Serializable{
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
      private String key;
      @ManyToOne(cascade = CascadeType.ALL)
      private User author;
      @OneToMany(cascade = CascadeType.ALL)
      private List&lt;Comment&gt; comments;
  </code></pre>
  
  <p>Now when I am trying to save a new User, the following exception occurs </p>
  
  <pre><code>Invalid primary key for User.  Cannot have a null primary key field if the field is unencoded and of type String.  Please provide a value or, if you want the datastore to generate an id on your behalf, change the type of the field to Long. 
  </code></pre>
  
  <p>Is it possible to let the String ID get generated without manually using the KeyFactory? If yes whats wrong with my code?</p>
  
  <p>thanks</p>