0

In AppEngine I need to have an entity Diagram that contains an id, title and a variable list of elements of inner class Box, each one with id and description.

Please find below the definition. However, at time of defining the EntityProxy List getter and setter: "The type java.util.List<Box> cannot be used here".

DIAGRAM.java

@Entity
public class Diagram extends DatastoreObject {

    public class Box {
    private String boxId;
    private String description;
    public String get_id() {
        return boxId;
    }
    public void set_id(String boxId) {
        this.boxId = boxId;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }

    @Indexed private String diagramId; // Primary key
    @Indexed private String title;
    @Embedded private List<Box> boxes;

    public String get_id() {
        return diagramId;
    }
    public void set_id(String diagramId) {
        this.diagramId = diagramId;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public void setBoxes(List<Box> boxes) {
        this.boxes = boxes
    }
    public List<Box> getBoxes() {
        return boxes;
    }
}

DIAGRAMPROXY.java

[...]
    List<Box> getBoxes();
    void setBoxes(List<Box> boxes);
[...]
4

2 回答 2

2

你的内部类必须是static. 非静态内部类具有到外部类实例的隐式链接,从将实体加载和保存到数据存储区的角度来看,这确实令人困惑。

于 2013-10-28T15:24:42.907 回答
0

令人困惑的是,您Collection<Box>在 Box 类中有一个吗?听起来不对。无论如何,内部 Box 类必须是市场static或移动到不同的文件。在 Box 类上使用@Embed(4.0 版)注释。

此外,假设DatastoreObject是所有实体的基础,您可以将其DatastoreObject作为 an@Entity并将其所有子类作为@EntitySubClass (index = true). 显然,所有子实体都将保存在数据存储中的相同“种类”(DatastoreObject)下。

于 2013-10-28T17:26:45.023 回答