No, that method takes a Base64 encoded encoded key string (something long)
and turns it into a Key instance. You want to use createKey:

http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.html#createKey(java.lang.String,
java.lang.String)

<http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.html#createKey(java.lang.String,
java.lang.String)>This is also documented here:

http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Creating_and_Using_Keys


On Fri, Apr 9, 2010 at 3:39 AM, stsch77 <[email protected]> wrote:

> Thanks for your reply. I changed
>
> person.setId("stsch");
>
> to
>
> person.setId(KeyFactory.stringToKey("stsch"));
>
> and
>
> @Id
>        private String id;
>
> to
>
> @Id
>        Key String id;
>
> but I am still getting the same error:
>
> java.lang.IllegalArgumentException: Cannot parse: stsch===
>        at
> com.google.appengine.api.datastore.KeyFactory.stringToKey(KeyFactory.java:
> 192)
>        at
>
> de.stsch.spring.appengine.SpringAppEngineController.get(SpringAppEngineController.java:
> 34)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> 39)
>        at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
> 25)
>        at java.lang.reflect.Method.invoke(Method.java:597)
>
>
>
>
>
> On 8 Apr., 19:14, "Ikai L (Google)" <[email protected]> wrote:
> > Check out this set of Javadocs:
> http://code.google.com/appengine/docs/java/javadoc/com/google/appengi...
> >
> > Key yourKey = KeyFactory.stringToKey("yourStringHere");
> >
> >
> >
> >
> >
> > On Thu, Apr 8, 2010 at 3:26 AM, stsch77 <[email protected]> wrote:
> > > I have tried to follow the documentation at
> >
> > >http://code.google.com/intl/de-DE/appengine/docs/java/datastore/creat.
> ..
> >
> > > 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");
> > > <<<EntityManager>>>.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.checkForParen­tSwitch(DatastoreRelationFieldManager.java:
> > > 201)
> > >        at
> >
> > >
> org.datanucleus.store.appengine.DatastoreFKListStoreSpecialization.updateEl­ementFk(DatastoreFKListStoreSpecialization.java:
> > > 94)
> > >        at
> >
> > >
> org.datanucleus.store.mapped.scostore.FKListStore.updateElementFk(FKListSto­re.java:
> > > 254)
> > > ...
> > > Caused by:
> >
> > >
> com.google.appengine.repackaged.com.google.common.util.Base64DecoderExcepti­on:
> > > 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
> > > [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected]<google-appengine-java%[email protected]>
> <google-appengine-java%2b­[email protected]>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-appengine-java?hl=en.
> >
> > --
> > Ikai Lan
> > Developer Programs Engineer, Google App Enginehttp://
> googleappengine.blogspot.com|http://twitter.com/app_engine- Zitierten Text
> ausblenden -
> >
> > - Zitierten Text anzeigen -
>
> --
> 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]<google-appengine-java%[email protected]>
> .
> 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 [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.

Reply via email to