Both following syntaxes are ok for JDO : Key key1 = KeyFactory.createKey(YourClass.class.getSimpleName(), 12345L); //using Long
Key key2 = KeyFactory.createKey(YourClass.class.getSimpleName(), "yourtextid"); //using String It's up to you to define how you want your entities to be recorded : 1. Either you let the datastore generate a key for you when recording a new entity => its key will be based on a Long 2. Or you 'force' the key with your own stringID or your own longID From: giannisdag <pascoua...@gmail.com> Reply-To: <google-appengine-java@googlegroups.com> Date: Wed, 3 Nov 2010 11:24:10 -0700 (PDT) To: <google-appengine-java@googlegroups.com> Subject: [appengine-java] Re: Query for a Long id using getObjectById JDO After doing some reading, I realized that in GAE datastore, an entity is stored using the key value and a key name or ID. The key name has to be a string and the ID is long. The key name can be created by the application and can be created like this as an example: Key key = KeyFactory.createKey(Employee.class.getSimpleName(), "alfred.sm...@example.com"); The ID can only be created by the datastore, so we have to leave it with a null value. Now, when we want to retrieve-fetch an object from datastore, we have two different situations. First, if we had created the entityid with key name, we can retrieve the object by recreating the key with the above syntax and then search for the object using Employee e = pm.getObjectById(Employee.class, k); But if we have used the numeric ID, we can' t look for it using the KeyFactory, as usually humans don' t search an object using numbers, but easily remembered strings. So we have to use a query. In my question, I have to use a query. If I am somewhere wrong, please inform me. -- 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. -- 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.