【问题标题】:Parent Entity Google Cloud API父实体 Google Cloud API
【发布时间】:2014-07-23 07:52:15
【问题描述】:

我会解释一下情况。我遵循了这两个伟大的教程:

但是,它们解释了如何为 Google Cloud Endpoint 创建 API,实体之间相互独立。所以 API 类看起来像这样:

package com.example.mobileassistant;

import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * Offer entity.
 */
@Entity
public class Offer {
  @Id
  private String offerId;

  private String title;

  private String description;

  private String imageUrl;

.... (With Getter and Setter)  

}

我的问题是:如何创建一个具有另一个父实体的类? 就像实体轮子一样,带有父汽车。我无法与其父实体创建关系(带有注释)!

我试过了,但它似乎不起作用(外键):

package com.example.mobileassistant;

import javax.jdo.annotations.ForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * Offer entity.
 */
@Entity
public class Wheel {
  @Id
  private String Id;

  @ForeignKey
  private String parent_id;

  private String title;

  private String description;


   .... (With Getter and Setter)  

}

【问题讨论】:

    标签: google-app-engine jpa google-cloud-endpoints google-cloud-datastore


    【解决方案1】:

    实际上,我已经放弃了 JDO,因为它并不真正支持父实体,就像我可以在这里阅读:http://www.igorkromin.net/index.php/2013/03/14/jdo-youre-dumped-app-engine-and-bi-directional-relationships/

    所以我现在将 Objectify 与 Google Cloud Endpoint(适用于我的 Android 应用程序)一起使用,效果非常好,尤其是在父/子关系方面!您可以在此处阅读示例:http://blog.xebia.fr/2014/06/23/google-app-engine-cloud-endpoint-creer-notre-api-v2-et-lutiliser-avec-angularjs/

    【讨论】:

      【解决方案2】:

      为什么你把它放在那里? 看到这个页面 http://www.datanucleus.org/products/accessplatform/jpa/annotations.html#ForeignKey 这解释得很清楚,它是 JoinColumn、JoinTable、CollectionTable、SecondaryTable 注释的一部分。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-08-14
        • 1970-01-01
        • 1970-01-01
        • 2020-08-20
        • 1970-01-01
        • 1970-01-01
        • 2021-12-11
        相关资源
        最近更新 更多