Hi,
This is what I do/did. Sadly, my method requires commenting and
commenting out for each persistent entity class, but I could not get
pre-compilation directives to work (quickly), so I lost patience with
that approach.
Enjoy(?)
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
public class Stuff 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;
}
//*** Change any list orderings from loID to sEncodedKey ***
//
//////////////////////////////////////////////////////////////////////////////
/*
//////////////////////////////////////////////////////////////////////////////
// This block is required for MySQL only, and will not work
// for Google BigTable.
//
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long loID;
*** Change any list orderings from sEncodedKey to loID ***
//
//////////////////////////////////////////////////////////////////////////////
*/
//@Persistent
//...
// Getter and setter methods
//...
}
On Sep 20, 4:10 pm, Daniel Ruiz Giménez <[email protected]>
wrote:
> Hi all,
>
> I'm experiencing some problems using "gae.encoded-pk" on MySQL.
>
> Reading the documentation (http://code.google.com/intl/en/appengine/
> docs/java/datastore/creatinggettinganddeletingdata.html) I found that:
>
> "Encoded string keys allow you to write your application in a portable
> manner..."
>
> but I can't find any information on how to achieve this. Consider this
> sample code from the docs:
>
> @PrimaryKey
> @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> @Extension(vendorName="datanucleus", key="gae.encoded-pk",
> value="true")
> private String encodedKey;
>
> This will work on appengine, but if used on an alternative stack of
> DataNucleus + MySQL, then it won't work (the automatic schema tool
> ignored the extension, and attempts to create a varchar column with an
> AUTO_INCREMENT attribute, which makes no sense).
>
> Does anybody know how to achieve the desired behaviour?
>
> Many thanks in advance!!
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" 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-java?hl=en.