【问题标题】:Owned relationships in Google App Engine not workingGoogle App Engine 中的自有关系不起作用
【发布时间】:2011-07-05 21:18:15
【问题描述】:

我正在从事一个 Google App Engine 项目,我正在努力让 JDO 中的关系正常工作。对象已正确保存,但相关对象未显示在数据存储查看器或查询中。

我的代码的修剪示例是:


        @PersistenceCapable
        public class Project implements Persistable {


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

    @Persistent(defaultFetchGroup = "true")
    private Client client;

        // Extra fields and getter and setters remove

        }

        @PersistenceCapable
        public class Client implements Persistable {

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

Representation r = null;
        PersistenceManager pm = PMF.get().getPersistenceManager();

        try {
            XMLToObject p = new XMLToObject(new org.everglade.tempus.persistence.dataobjects.Project());
            p.parse(xml);
            org.everglade.tempus.persistence.dataobjects.Project proj = (org.everglade.tempus.persistence.dataobjects.Project) p.getObject();
            pm.makePersistent(proj);
            getResponse().setStatus(Status.SUCCESS_CREATED);
            getResponse().setLocationRef("/project/" + KeyFactory.keyToString(proj.getId()));
        } catch (Exception e) { // Add finer exception handling here so can alter status based on what went wrong!
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
            Log.severe("The following error occurred whilst trying to add a new project: " + e.getMessage());
        } finally {
            pm.close();
        }

保存了一个项目对象,但没有与之关联的客户端 - 任何人都知道为什么吗?这是我在应用引擎上的第一个应用,也使用 JDO,所以它可能非常明显!

提前致谢!

【问题讨论】:

    标签: java google-app-engine persistence jdo


    【解决方案1】:

    您应该知道,App Engine 上的自有关系与 JDO 规范有很大不同。拥有的关系实际上创建了一个实体组,它是一个存储图。更多信息在这里http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html

    因此,在大多数情况下,在应用引擎上,您最好通过 Key 引用其他对象。除非您真的打算定义实体组图。同样,我建议您避免使用大型继承树(上面相同参考链接中的信息)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 2012-07-19
      相关资源
      最近更新 更多