0
votes

I'll explain the situation. I followed these two great tuto:

However, they explain how create API for Google Cloud Endpoint, with entities independent from each other. So the API class looks like this:

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)  

}

My question is: How to create a class with a parent entity of another? Like the entitie Wheel, with Parent Car. I can not create a relationship with its parent entity (With the annotation)!

I tried this but it did not seem to work (Foreign Key):

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)  

}
2

2 Answers

1
votes

Actually, I have given up JDO because it don't really support parent entity, like I can read here: http://www.igorkromin.net/index.php/2013/03/14/jdo-youre-dumped-app-engine-and-bi-directional-relationships/

So I'm using now Objectify with Google Cloud Endpoint (For my Android App) and It works so perfect, especially with parent/child relationship !! You can read example here: http://blog.xebia.fr/2014/06/23/google-app-engine-cloud-endpoint-creer-notre-api-v2-et-lutiliser-avec-angularjs/

0
votes

Why would it when you put it there? See this page http://www.datanucleus.org/products/accessplatform/jpa/annotations.html#ForeignKey which explains clear enough that it is part of the JoinColumn, JoinTable, CollectionTable, SecondaryTable annotations.