0

我们将 GAE 与 JDO2.3 一起使用,并具有以下代码:

public void submit_job (HttpSession session, BlobKey blobKey) throws Exception {
  // START TRANSACTION
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Transaction tx = pm.currentTransaction();
  tx.begin();

  // GET JOB AND MEMBER FROM DATASTORE
  Key jobKey = (Key)session.getAttribute("jobkey");
  String userName = session.getAttribute("username").toString();

  Job job = pm.getObjectById(Job.class, jobKey);
  Member m = pm.getObjectById(Member.class, username);

  // STORE JOB INFORMATION IN DATASTORE
  Date now = new Date();
  job.caricature = blobKey;
  job.whenSubmitted = now;
  job.whenFinished = now;
  pm.makePersistent(job);
  pm.flush();
  log.warning("submit_job: updating job " + job.key);

  // UPDATE MEMBER INFORMATION
  m.numSubmittedJobs++;
  pm.makePersistent(m);
  pm.flush();    
  log.warning("submit_job: updating user " + username);

  // COMPLETE TRANSACTION
  tx.commit();
  pm.close();
  log.warning("transaction completed? " + !tx.isActive());
}

症状:

  • 不抛出异常,一切正常
  • 最后,交易正确完成(“交易完成?真”)
  • 以下查询可以从 Member 和 Job 对象中读取更新的数据

  • 该信息未显示在数据存储管理器中
  • 重新启动实例后,JDO 对象具有其旧值。所有更改都将丢失。

这是我们的 jdoconfig.xml:

<?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"/>
       <property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
   </persistence-manager-factory>
</jdoconfig>

和persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence
    xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">

    <persistence-unit name="transactions-optional">
        <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
        </properties>
    </persistence-unit>
</persistence>

感谢您的帮助,我们已经在这个主题上付出了很多努力,但还无法解决它。

谢谢!

4

1 回答 1

1

So you're setting public fields of a persistable class, and somehow expect the persistence mechanism to know about this. As per the JDO spec, you should use setters, or annotate the class doing the setting as PersistenceAware.

And look at the log too, since it tells you what is happening

于 2013-05-06T07:50:23.263 回答