Search code examples
google-app-enginejdo

What is "name=" for in Google App Engine Data Store Key Field


The User class is defined as below

 @PersistenceCapable(detachable="true")
public class User {
    @PrimaryKey
    @Persistent
    private String email;

    @Persistent
    private String firstname;

    @Persistent
    private String lastname;

In PROD, I added a user with email="david12@gmail.com", firstname=something, lastname=something via JDO. Then in Datastore Viewer, the ID/Name field has a value of "Name=david12@gmail.com". Why was "Name=" added? My program cannot find user with key = "david12@gmail.com". It can in my DEV PC though where there is never "Name=".

[Added source code of retrieving a User instance] It works well in my DEV PC.

    public static User getUser(String email){
    PersistenceManager pm = PMF.get().getPersistenceManager();
    User user, detached = null;
    try {
        user = pm.getObjectById(User.class,
            email);

        // If you're using transactions, you can call
        // pm.setDetachAllOnCommit(true) before committing to automatically
        // detach all objects without calls to detachCopy or detachCopyAll.
        detached = pm.detachCopy(user);
    } 
    catch(Exception e){
        e.printStackTrace();
    }
    finally {
        pm.close();
    }
    return detached;
}

enter image description here

![enter image description here][2]


Solution

  • Since the id can be either an auto-generated number or a custom string, "name=" is there to make it clear the id is a string (otherwise you would get a "id=").

    As for not finding the user, the problem must be in how the query is made, so we would need more insight into your code to figure it out.