5

当我创建一个定义“gae.encoded-pk”和“gae.pk-id”持久的类时,编码的pk被更新,但id保持为空。没有抛出异常,代码是谷歌文档的直接复制粘贴,所以我对这里可能发生的事情感到茫然。

该类定义:

@PersistenceCapable 
public class MyClass {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String encodedKey;

    @Persistent
    @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
    private Long keyId;

我让它像这样持久化:

PersistenceManager pm = PMF.get().getPersistenceManager();
try {
    pm.makePersistent(myInstance);
    // myInstance = pm.makePersistent(myInstance); - Produces the same result.
} finally {
    pm.close();
}

我正在使用调试器单步执行此代码,但 keyId 仍然为空,即使在持久性管理器关闭后也是如此。

我还应该指出,这是使用 google appengine 开发工具包在本地运行的。任何关于我如何调试它的指针将不胜感激!

4

1 回答 1

1

I found this answer:

The GAE JDO plugin only ever sets a "gae.pk-id"/"gae.pk-name" field when it reads in a field marked with that from the datastore (just do a search in SVN trunk, FetchFieldManager is the only place where it's loaded - it doesn't set it when it does a PUT). No idea what it did in 1.x, but all of GAE's own tests pass in 2.x as they did in 1.x. But then that "feature" isn't standard JDO anyway, so of little interest to me.

See: Unable to get ID of newly-created JDO persistent entity using GAE/J DataNucleus plug-in version 2.1.2

于 2015-02-06T05:48:30.803 回答