Re: [appengine-java] JPA: How to use a String as Primary Key?

2010-04-08 Thread Ikai L (Google)
Check out this set of Javadocs:
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.Builder.html

Key yourKey = KeyFactory.stringToKey("yourStringHere");

On Thu, Apr 8, 2010 at 3:26 AM, stsch77  wrote:

> I have tried to follow the documentation at
>
>
> http://code.google.com/intl/de-DE/appengine/docs/java/datastore/creatinggettinganddeletingdata.html
>
> but no matter what I try, I always get an error/an exception of
> different kinds.
>
> Already the simplest attempt comes up with an error. That's what i
> have:
>
> - - - - -
>
> public class Person {
>
>@Id
>private String id;
>
> - - - - -
>
> ...
> person.setId("stsch");
> <<>>.persist(person);
> ...
>
> - - - - -
>
> ==>
>
> java.lang.IllegalArgumentException: Cannot parse: stsch===
>at
> com.google.appengine.api.datastore.KeyFactory.stringToKey(KeyFactory.java:
> 192)
>at
>
> org.datanucleus.store.appengine.DatastoreRelationFieldManager.checkForParentSwitch(DatastoreRelationFieldManager.java:
> 201)
>at
>
> org.datanucleus.store.appengine.DatastoreFKListStoreSpecialization.updateElementFk(DatastoreFKListStoreSpecialization.java:
> 94)
>at
>
> org.datanucleus.store.mapped.scostore.FKListStore.updateElementFk(FKListStore.java:
> 254)
> ...
> Caused by:
>
> com.google.appengine.repackaged.com.google.common.util.Base64DecoderException:
> invalid padding byte '=' at byte offset 5
>at
>
> com.google.appengine.repackaged.com.google.common.util.Base64.decode(Base64.java:
> 529)
>at
>
> com.google.appengine.repackaged.com.google.common.util.Base64.decodeWebSafe(Base64.java:
> 493)
>at
> com.google.appengine.api.datastore.KeyFactory.stringToKey(KeyFactory.java:
> 190)
>
>
> What is necessary to use a String as Primary Key?
>
> --
> 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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>


-- 
Ikai Lan
Developer Programs Engineer, Google App Engine
http://googleappengine.blogspot.com | http://twitter.com/app_engine

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] JPA: How to use a String as Primary Key?

2010-04-08 Thread stsch77
I have tried to follow the documentation at

http://code.google.com/intl/de-DE/appengine/docs/java/datastore/creatinggettinganddeletingdata.html

but no matter what I try, I always get an error/an exception of
different kinds.

Already the simplest attempt comes up with an error. That's what i
have:

- - - - -

public class Person {

@Id
private String id;

- - - - -

...
person.setId("stsch");
<<>>.persist(person);
...

- - - - -

==>

java.lang.IllegalArgumentException: Cannot parse: stsch===
at
com.google.appengine.api.datastore.KeyFactory.stringToKey(KeyFactory.java:
192)
at
org.datanucleus.store.appengine.DatastoreRelationFieldManager.checkForParentSwitch(DatastoreRelationFieldManager.java:
201)
at
org.datanucleus.store.appengine.DatastoreFKListStoreSpecialization.updateElementFk(DatastoreFKListStoreSpecialization.java:
94)
at
org.datanucleus.store.mapped.scostore.FKListStore.updateElementFk(FKListStore.java:
254)
...
Caused by:
com.google.appengine.repackaged.com.google.common.util.Base64DecoderException:
invalid padding byte '=' at byte offset 5
at
com.google.appengine.repackaged.com.google.common.util.Base64.decode(Base64.java:
529)
at
com.google.appengine.repackaged.com.google.common.util.Base64.decodeWebSafe(Base64.java:
493)
at
com.google.appengine.api.datastore.KeyFactory.stringToKey(KeyFactory.java:
190)


What is necessary to use a String as Primary Key?

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.