Hi Andreas,
The field mapped with the "gae.parent-pk" is expected to hold a Key
value or a key value encoded as string. Try this:
....
public ShoppingList(Shopper shopper) {
Key shopperKey =
KeyFactory.createKey(Shopper.class.getSimpleName(),
shopper.getEmail());
shopperEmail = KeyFactory.keyToString(shopperKey);
}
...
Of course the shopperEmail field will not contain the email anymore,
but the key of the shopper encoded as a string. You can still retrieve
the email by converting it to a Key and calling Key.getName()
(KeyFactory.stringToKey(shopperEmail).getName()).
Marton
On Sep 24, 3:13 pm, Andreas Kristensson
<[email protected]> wrote:
> Hi,
>
> Trying to create ShoppingList child objects with parent set to
> Shopper. Persisting Shopper works fine, but when I have created a
> ShoppingList and tries to persist it I get the following exception:
>
> javax.jdo.JDOFatalUserException: Attempt was made to set parent to
> [email protected] but this cannot be converted into a Key.
>
> Well, email works fine as key in Shopper. Why won't it play nice with
> extension gae.parent-pk? Anyone?
>
> ++ Code snippet
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> Shopper
> {
> @PrimaryKey
> private String email;
>
> ...
>
> public Shopper(String email)
> {
> this.email = email;
> }
>
> }
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> ShoppingList
> {
> @PrimaryKey
> @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> private Key key;
>
> @Persistent
> @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value
> = "true")
> private String shopperEmail;
>
> ...
>
> public ShoppingList(Shopper shopper)
> {
> shopperEmail = shopper.getEmail();
> }
>
> }
>
> ++ End of code snippet
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---