Hello Ivanceras,

Data type for primary keys (PKs)
--------------------------------
When I use Key as Encoded String for my PKs, the data type of the PK
is java.lang.String! I give a snippet below to demonstrate this for
me:


@PersistenceCapable(identityType = IdentityType.APPLICATION,
 detachable = "true")
public class NoticePageHome implements Serializable
{
  private static final long serialVersionUID = 1L;


  /*
  //////////////////////////////////////////////////////////////////////////////
  // This block is required since this entity has an entity group
root.
  // It does not work with MySQL, so we use an alternative for that
database.
  // We have the getter method for getting the encoded key here for
convenience.
  //

  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  @Extension(vendorName="datanucleus", key="gae.encoded-pk",
value="true")
  private String sEncodedKey;

  @Persistent
  @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
  private Long loID;

  public String getEncodedKey()
  {
    return sEncodedKey;
  }

  //
  //////////////////////////////////////////////////////////////////////////////
  */


  //////////////////////////////////////////////////////////////////////////////
  // This block is required for MySQL only, and will not work
  // for Google BigTable.
  //

  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Long loID;

  //
  //////////////////////////////////////////////////////////////////////////////


  /*
    Data fields, getters and setters...
  */


Please note:
1.  I switch PK blocks depending on whether I am using GAE or MySQL.
2.  Using GAE (with Key as Encoded String), I have both the String
encoded key and the Long ID produced automatically by GAE.
3.  I trust that this PK method would be easily portable to non-GAE
datastores, should the need ever arise in the future.


I would prefer to use BigTable as much as possible, but I need to use
MySQL when running my Apache Wicket web app in development mode, which
is useful to catch silly mark-up mismatch bugs, amongst others.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to