Java 存储对象后检索对象时出错

Java 存储对象后检索对象时出错,java,google-app-engine,jdo,Java,Google App Engine,Jdo,我有两个servlet: 其中我存储了一个用户: pm = PMF.get().getPersistenceManager(); Key key = KeyFactory.createKey(PersistentUser.class.getSimpleName(), "alfred"); PersistentUser user = new PersistentUser(); user.setKey(key); user.setLogin("alfred")

我有两个servlet:

其中我存储了一个用户:

    pm = PMF.get().getPersistenceManager();
    Key key = KeyFactory.createKey(PersistentUser.class.getSimpleName(), "alfred");
    PersistentUser user = new PersistentUser();
    user.setKey(key);
    user.setLogin("alfred");

    try {
         pm.makePersistent(user);
    } finally {
         pm.flush();
         pm.close();
    }
还有一个我想读的地方:

    pm = PMF.get().getPersistenceManager();
    Key k = KeyFactory.createKey(PersistentUser.class.getSimpleName(), "alfred");
    PersistentUser e;
    try {
        e = pm.getObjectById(PersistentUser.class, k);
        log.info(e.getLogin());
        response.getOutputStream().println(e.getLogin());
    } finally {
        pm.flush();
        pm.close();
    }
因此,在使用户持久化时,我没有遇到任何问题,但我无法在另一个servlet中检索对象,因此出现以下错误:

javax.jdo.JDOObjectNotFoundException:无法检索具有关键PersistentUser(“登录”)的PersistentUser类型的实体

我使用的是标准的PMF类。我的PersistentUser类如下所示:

@PersistenceCapable
public class PersistentUser implements Serializable{

    @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;

    @Persistent
    private String login;

    public PersistentUser() {}

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public Key getKey() {
        return key;
    }

    public void setKey(Key key) {
        this.key = key;
    }
}

我的jdoconfig文件是:

<?xml version="1.0" encoding="utf-8"?>
    <jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">

       <persistence-manager-factory name="transactions-optional">
           <property name="javax.jdo.PersistenceManagerFactoryClass"value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
           <property name="javax.jdo.option.ConnectionURL" value="appengine"/>
           <property name="javax.jdo.option.NontransactionalRead" value="true"/>
           <property name="javax.jdo.option.NontransactionalWrite" value="true"/>
           <property name="javax.jdo.option.RetainValues" value="true"/>
           <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
           <property name="datanucleus.appengine.singletonPMFForName" value="true"/>
       </persistence-manager-factory>
    </jdoconfig>

什么是
u.getLogin()
,它与硬编码字符串
“alfred”
以及后面对
usr.setLogin(“alfred”)的调用有什么关系?
u
user
usr
之间的关系如何?我的错误是,它们是相同的。我编辑了,谢谢